Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

protractor-flake finds the typescript file (not the compiled file) on retry #107

Open
mathpunk opened this issue Feb 19, 2019 · 5 comments

Comments

@mathpunk
Copy link

This might be a documentation problem rather than a parser problem. I discovered that protractor-flake was rerunning all of my tests rather than the failed ones, so I tried a small test with one spec deliberately set to fail. Here was the command and the resultant output:

$ ./node_modules/protractor-flake/bin/protractor-flake --max-attempts=3 -- e2e/dist/e2e/conf.js --capabilities.chromeOptions.args=[] --suite login

[12:09:20] I/launcher - Running 1 instances of WebDriver
[12:09:20] I/direct - Using ChromeDriver directly...
Started
problem trying to remove a folder:./reports/
.F

Failures:
1) LogicGate landing page allows an admin to log in
  Message:
    Expected true to be falsy.
  Stack:
    Error: Failed expectation
        at UserContext.<anonymous> (/home/man/logicgate/dev/logicgate/platform/client/e2e/specs/access/login.spec.ts:25:48)
        at /home/man/logicgate/dev/logicgate/platform/client/node_modules/jasminewd2/index.js:112:25
        at new ManagedPromise (/home/man/logicgate/dev/logicgate/platform/client/node_modules/selenium-w
ebdriver/lib/promise.js:1077:7)
        at ControlFlow.promise (/home/man/logicgate/dev/logicgate/platform/client/node_modules/selenium-webdriver/lib/promise.js:2505:12)
        at schedulerExecute (/home/man/logicgate/dev/logicgate/platform/client/node_modules/jasminewd2/index.js:95:18)
        at TaskQueue.execute_ (/home/man/logicgate/dev/logicgate/platform/client/node_modules/selenium-webdriver/lib/promise.js:3084:14)
        at TaskQueue.executeNext_ (/home/man/logicgate/dev/logicgate/platform/client/node_modules/selenium-webdriver/lib/promise.js:3067:27)
        at asyncRun (/home/man/logicgate/dev/logicgate/platform/client/node_modules/selenium-webdriver/lib/promise.js:2974:25)
        at /home/man/logicgate/dev/logicgate/platform/client/node_modules/selenium-webdriver/lib/promise.js:668:7

2 specs, 1 failure
Finished in 39.771 seconds


[12:10:03] I/launcher - 0 instance(s) of WebDriver still running
[12:10:03] I/launcher - chrome #01 failed 1 test(s)
[12:10:03] I/launcher - overall: 1 failed spec(s)
[12:10:03] E/launcher - Process exited with error code 1

Using standard to parse output
Re-running tests: test attempt 2

So far so good. But check this out: Continuing,

Re-running the following test files:
/home/man/logicgate/dev/logicgate/platform/client/e2e/specs/access/login.spec.ts
[12:10:03] I/launcher - Running 1 instances of WebDriver
[12:10:03] I/direct - Using ChromeDriver directly...
[12:10:05] E/launcher - Error: /home/man/logicgate/dev/logicgate/platform/client/e2e/specs/access/login.spec.ts:1
(function (exports, require, module, __filename, __dirname) { import { Timings } from '../../models/timings';
                                                                     ^

SyntaxError: Unexpected token {
    at new Script (vm.js:84:7)
    at createScript (vm.js:264:10)
    at Object.runInThisContext (vm.js:312:10)
    at Module._compile (internal/modules/cjs/loader.js:696:28)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:747:10)
    at Module.load (internal/modules/cjs/loader.js:628:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:568:12)
    at Function.Module._load (internal/modules/cjs/loader.js:560:3)
    at Module.require (internal/modules/cjs/loader.js:665:17)
    at require (internal/modules/cjs/helpers.js:20:18)
[12:10:05] E/launcher - Process exited with error code 100

Using standard to parse output
Re-running tests: test attempt 3

Tests failed but no specs were found. All specs will be run again.

[12:10:06] I/launcher - Running 1 instances of WebDriver
[12:10:06] I/direct - Using ChromeDriver directly...
Started....

My read is, it looks like the first run correctly used my compiled conf.js to find the paths for the tests it needed to run, but on the subsequent run, it picked up the typescript file instead. Did I miss a flag somewhere in my command, or is this a genuine bug?

===============================================

  • OS: 4.14.98-1-MANJARO x86_64 GNU/Linux
  • Node: v11.8.0
  • "protractor": "^5.4.1",
  • "protractor-flake": "^4.0.0",
  • Protractor configuration file:
import { browser, Config } from 'protractor';

export let config: Config = {
  baseUrl: process.env.BASE_URL,
  capabilities: {
    browserName: 'chrome',
    chromeOptions: {
      args: ['--headless', '--disable-gpu', '--window-size=800,600'],
    },
  },
  directConnect: true,
  jasmineNodeOpts: {
    defaultTimeoutInterval: 260000,
    includeStackTrace: true,
    isVerbose: true,
    showColors: true,
  },
  onPrepare: () => {
    const Jasmine2HtmlReporter = require('protractor-jasmine2-html-reporter');
    const jasmineReporters = require('jasmine-reporters');

    return browser.getProcessedConfig().then(() => {
      jasmine.getEnv().addReporter(new jasmineReporters.JUnitXmlReporter({
        consolidateAll: true,
        displayStacktrace: 'specs',
        savePath: './reports/e2e/',
      }));

      jasmine.getEnv().addReporter(
        new Jasmine2HtmlReporter({
          displayStacktrace: 'specs',
          fileNameDateSuffix: true,
          fixedScreenshotName: true,
          savePath: './reports/',
          screenshotsFolder: 'screenshots',
          takeScreenshots: true,
          takeScreenshotsOnlyOnFailures: true,
        }),
      );

      browser.credentials = {
        email: process.env.ADMIN_ID,
        firstName: process.env.ADMIN_FIRSTNAME,
        lastName: process.env.ADMIN_LASTNAME,
        password: process.env.ADMIN_PASSWORD,
      };
      browser.waitForAngularEnabled(false);
      browser.manage().deleteAllCookies();
    });
  },
  suites: {
    access: 'specs/app/build/access/*.spec.js',
    fields: ['specs/app/build/processes/node/form/field/*.spec.js',
      'specs/app/build/processes/node/form/field/**/*.spec.js'],
    forms: 'specs/app/build/processes/node/form/*.spec.js',
    login: 'specs/access/login.spec.js',
    nodes: 'specs/app/build/processes/node/*.spec.js',
    paths: 'specs/app/build/processes/node/path/*.spec.js',
    processes: 'specs/app/build/processes/process/*.spec.js',
    queue: 'specs/app/main/queue/incident-management/*.spec.js',
    users: 'specs/app/admin/users/*.js',
  },
};
@NickTomlin
Copy link
Owner

The issue here is that the path in the stacktrace (which is what flake uses to choose what to re-run) is a ts one and not a js one:

at UserContext.<anonymous> (/home/man/logicgate/dev/logicgate/platform/client/e2e/specs/access/login.spec.ts:25:48)

I'm not sure if this is the default behavior, or something that is happening during transpilation. Can I get you to produce a small example repo? If it's an error with the project we can use that to create an integration test that we can use to build a fix against.

One short-term workaround would be to create your own custom parser, and just .replace the ts with js.

@sjmckinney
Copy link

I have a simple repo that exposes the issue if you're still in need of a test case.

@NickTomlin
Copy link
Owner

@sjmckinney that would be helpful, please share it if you still have it

@sjmckinney
Copy link

The url of the repo is: https://github.com/sjmckinney/34-protons-protractor-automation

There are two identical specs; login.spec.ts and login1.spec.ts. The former contains a failing test version of the test 'should show user page loading message whilst logging in' which will cause that spec to be repeated.

Running tsc with the current tsconfig.json should compile the .ts files to a './dist' sub-folder from where they will be run.

Change the value of 'parser' to 'standard' in the 'flake' script to demonstrate the issue as reported.

I have implemented a custom parser, 'my_parser.js' as a work around.

@NickTomlin
Copy link
Owner

thanks for this. I'm currently in a busy season at work and at home so I may not get to look at it for some time.

I'd welcome a pull request that bakes this into the standard parser (perhaps detecting ts paths and transforming them?) in the meantime!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants