Skip to content

TS Tests Aren't Run the First Time #2766

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

Closed
dtopuzov opened this issue May 4, 2017 · 2 comments
Closed

TS Tests Aren't Run the First Time #2766

dtopuzov opened this issue May 4, 2017 · 2 comments
Assignees
Milestone

Comments

@dtopuzov
Copy link
Contributor

dtopuzov commented May 4, 2017

From @joeskeen on October 12, 2016 16:15

tns version: 2.4.0-2016-10-06-6743
OS: OS X El Capitan 10.11.6

If you add a TypeScript unit test file (/app/tests/*.ts), it won't get executed on the first test run, only the second one. Steps to reproduce:

  • Clone the sample-Groceries repo and check out the angular-start branch

  • run tns test init using Jasmine as test framework. This will create a single JS test file under /app/tests.

  • run tns test ios. In the console you will see the following:

    Oct 12 08:46:07 AC02NPBKPG3QD sampleGroceries[6490]: CONSOLE LOG file:///app/tns_modules/nativescript-unit-test-runner/main-view-model.js:212:24: NSUTR: beginning test run
    NativeScript / 10.0 (10.0; iPhone): Executed 0 of 1 SUCCESS (0 secs / 0 secs)
    NativeScript / 10.0 (10.0; iPhone): Executed 1 of 1 SUCCESS (0.009 secs / 0.002 secs)
    Oct 12 08:46:07 AC02NPBKPG3QD sampleGroceries[6490]: CONSOLE LOG file:///app/tns_modules/nativescript-unit-test-runner/main-view-model.js:258:24: NSUTR: completeAck
    

    Note that it only runs one spec (the JS one that was already there). Go ahead and kill the test process.

  • create a file in /app/tests called myTest.ts, and add a simple test inside (you can copy/paste the code from the JS one and change some of the strings to make them unique). You also may have to add a type reference or declaration to get it to compile.

  • run tns test ios again. You will see it only runs one test (not recognizing the new one).

  • kill the process and run it again. This time you will see output like this:

    NativeScript / 10.0 (10.0; iPhone): Executed 0 of 2 SUCCESS (0 secs / 0 secs)
    NativeScript / 10.0 (10.0; iPhone): Executed 2 of 2 SUCCESS (0.013 secs / 0.002 secs)
    

So it appears that TS files in the /app/tests/ folder do get transpiled, but not until after the .js files are collected for testing by Karma. This means that if we want to use TS for testing in continuous integration, we have to run the test suite twice.

Copied from original issue: NativeScript/nativescript-unit-test-runner#22

@Fatme
Copy link
Contributor

Fatme commented Apr 1, 2019

Workaround:

tns test ios --bundle

@Fatme Fatme modified the milestones: 5.3.1, 6.0.0 Apr 1, 2019
@Fatme Fatme added the planned label Apr 1, 2019
@Fatme Fatme removed the planned label Apr 15, 2019
@endarova endarova modified the milestones: 6.0.0, 6.0.1 Jul 16, 2019
@rosen-vladimirov rosen-vladimirov modified the milestones: 6.0.1, 6.1.0 Jul 22, 2019
@Fatme
Copy link
Contributor

Fatme commented Oct 14, 2019

It seems that karma has been gathered tests files before running webpack compilation. Most probably the issue happens as we had the following inside karma.conf.js:

files: ['app/tests/**/*.js']

However, when using the bundle workflow, the error is totally different from the described one:

10 10 2019 11:34:38.105:ERROR [config]: Error in config file!
 Error: The specified path to app directory /Users/havaluova/Work/sample-Groceries/src does not exist. Unable to find entry module.
    at verifyEntryModuleDirectory (/Users/havaluova/Work/sample-Groceries/node_modules/nativescript-dev-webpack/index.js:163:15)
    at Object.exports.getEntryModule (/Users/havaluova/Work/sample-Groceries/node_modules/nativescript-dev-webpack/index.js:29:5)
    at module.exports.env (/Users/havaluova/Work/sample-Groceries/webpack.config.js:60:38)
    at setWebpack (/Users/havaluova/Work/sample-Groceries/karma.conf.js:102:50)
    at module.exports (/Users/havaluova/Work/sample-Groceries/karma.conf.js:77:3)
    at Object.parseConfig (/Users/havaluova/Work/sample-Groceries/node_modules/karma/lib/config.js:393:5)
    at new Server (/Users/havaluova/Work/sample-Groceries/node_modules/karma/lib/server.js:66:24)
    at process.on (/Users/havaluova/Work/nativescript-cli/lib/services/karma-execution.js:6:160)
    at process.emit (events.js:182:13)
    at emit (internal/child_process.js:812:12)
    at process._tickCallback (internal/process/next_tick.js:63:19)
Test run failed.

I logged this error as a separate issue here.

However, as the above steps are already outdated, they should be transformed to the following steps:

  • Clone the sample-Groceries repo
  • Run tns test ios
  • Go ahead and kill the test process.
  • Create a file in /app/tests called myTest.ts, and add a simple test inside like this:
declare var expect: any;

describe("my tests", function() {
    it("sample test 2", function () {
        expect(false).toBe(false);
    });
});
  • Run tns test ios again. You will see that all tests are ran.

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

No branches or pull requests

5 participants