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

How to include a file at the start of a Mocha run #2201

Closed
devonhumes opened this issue Sep 8, 2019 · 2 comments

Comments

@devonhumes
Copy link

commented Sep 8, 2019

Issue description or question

We have async setup code in a global before block in a Mocha test suite. We are including this file using the --file option to the Mocha CLI. How would we replicate this functionality in WallabyJS?

Is there a way that we can configure Mocha using a mocha configuration file?

Wallaby.js configuration file

// paste your config here

module.exports = function() {
    return {
        files: [ 
            // The file to include before all of the other files.
            { pattern: 'src/common/environment/environment.init.ts' },
            "src/**/*.ts"
        ],
        tests: [
            "tests/**/*.spec.ts"
        ],
        testFramework: 'mocha',
        env: {
            type: 'node',
        },
        setup: function(w) {
            const ui = require(path.resolve(process.cwd(), 'src/common/mocha/bdd'));
            w.testFramework.ui(ui);
        }
    }
}

Code editor or IDE name and version

Visual Studio Code v1.38.0
IntelliJ IDEA v2019.2

OS name and version

OSX

@devonhumes

This comment has been minimized.

Copy link
Author

commented Sep 8, 2019

I solved this by using the addFile function on the testFramework.


module.exports = function() {
    return {
        files: [
            "src/**/*.ts"
        ],
        tests: [
            "tests/**/*.spec.ts"
        ],
        testFramework: 'mocha',
        env: {
            type: 'node',
        },
        setup: function(w) {
            const path = require('path');

            const ui = require(path.resolve(process.cwd(), 'src/common/mocha/bdd'));
            w.testFramework.addFile(path.resolve(process.cwd(), 'src/common/environment/environment.init'));
            w.testFramework.ui(ui);
        }
    }
}

@devonhumes devonhumes closed this Sep 8, 2019

@ArtemGovorov

This comment has been minimized.

Copy link
Member

commented Sep 8, 2019

Awesome, thanks for the update. We'll update our docs at https://wallabyjs.com/docs/integration/node.html#mocha to include the scenario.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.