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

NodeJS with jasmine and jasmine-expect passes once then fails #786

Closed
jessezhang91 opened this Issue Sep 11, 2016 · 1 comment

Comments

Projects
None yet
2 participants
@jessezhang91

jessezhang91 commented Sep 11, 2016

Issue description or question

I'm not sure if I'm requiring jasmine-expect correctly but my assertions like expect(arr).toBeArrayOfObjects(); seem to be passing the first time. Subsequent runs of the spec causes it to throw ​​expect(...).toBeArrayOfObjects is not a function​​. If I stop and start wallaby, the test passes again.

Wallaby.js configuration file

"use strict";

module.exports = (w) => {
    return {
        files: [
            "src/**/*.ts",
            "test/**/!(*.spec).ts"
        ],
        tests: [
            "test/**/*.spec.ts"
        ],
        compilers: {
            "**/*.ts": w.compilers.typeScript({
                target: "es5",
                module: "commonjs",
                typescript: require("typescript")
            })
        },
        env: {
            type: "node"
        },
        testFramework: "jasmine",
        setup: (w) => {
            require("jasmine-expect");
            w.testFramework.DEFAULT_TIMEOUT_INTERVAL = 2500;
        }
    }
};

Code editor or IDE name and version

Visual Studio Code v1.5.1

OS name and version

Windows

@ArtemGovorov

This comment has been minimized.

Show comment
Hide comment
@ArtemGovorov

ArtemGovorov Sep 12, 2016

Member

Wallaby.js reuses node processes by default and jasmine-expect is built in such a way that it only adds matchers once per process, so when the setup function executes require("jasmine-expect"); second time in the same process, nothing happens.

The easiest way to test if it's an issue for any scenario/module is to try and set workers.recycle setting to true to make wallaby.js re-start node process for each run. If it works fine with the setting, you may either keep using it, or try resetting the node cache for the module so that it can work even with the process re-use (which is more performant than restarting node processes).

By quickly trying, here is the solution that seems to work in this specific case:

    setup: (w) => {
      Object.keys(require.cache).filter(k => k.indexOf('jasmine-expect') >= 0)
        .forEach((k) => { delete require.cache[k]; });

      require("jasmine-expect");
      w.testFramework.DEFAULT_TIMEOUT_INTERVAL = 2500;
    },

I just delete the jasmine-expect module from the node cache before require-ing it.

Member

ArtemGovorov commented Sep 12, 2016

Wallaby.js reuses node processes by default and jasmine-expect is built in such a way that it only adds matchers once per process, so when the setup function executes require("jasmine-expect"); second time in the same process, nothing happens.

The easiest way to test if it's an issue for any scenario/module is to try and set workers.recycle setting to true to make wallaby.js re-start node process for each run. If it works fine with the setting, you may either keep using it, or try resetting the node cache for the module so that it can work even with the process re-use (which is more performant than restarting node processes).

By quickly trying, here is the solution that seems to work in this specific case:

    setup: (w) => {
      Object.keys(require.cache).filter(k => k.indexOf('jasmine-expect') >= 0)
        .forEach((k) => { delete require.cache[k]; });

      require("jasmine-expect");
      w.testFramework.DEFAULT_TIMEOUT_INTERVAL = 2500;
    },

I just delete the jasmine-expect module from the node cache before require-ing it.

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