-
Notifications
You must be signed in to change notification settings - Fork 241
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
Improve Mocha support #1046
Comments
Thanks for reporting this issue. I see that you have both a webpack configuration and a Babel configuration. You normally won't need webpack when using mocha as a test runner. What does your babelrc and npm test command look like? |
@nicojs the post was edited after placing it. The webpack config is now gone and the post mentions they don't use webpack. (I was about to ask the same question) |
Sorry about the mistake in the config file, I did edit it right after I noticed it. Here is my babelrc and npm test command. babelrc
npm test command"test": "cross-env NODE_ENV=test mocha "./test/**/*-tests.js"", |
As a check, could you upgrade the Stryker dependencies to their latest versions? If you use Git for this project, you may be able to remove the |
Sorry for taking so long to reply. I was able to update Stryker to the latest version, but may have to wait till Monday till the other dependencies can be updated. I tried running with just the updated Stryker and got this error: module.js:440 Error: Cannot find module 'stryker-api/logging' Trying to delete the old conf file and running init again also results in the same error. I'm thinking I'll have to update stryker-api at least before I can do anything more. |
Yeah, we've recently revamped the logging so you'll have to update all Stryker dependencies (including the plugins such as stryker-mocha-runner). Don't worry about taking a while to respond. We're here to help you and if you need some time that's perfectly fine. We also don't have time to reply or fix things right away :) |
I installed the upgraded dependencies this morning and reran the init command. The only thing the setup asked me was what type of reporters I wanted and the package manager I was using. The config file had a few labels with nothing filled in so I filled it in. I'm still receiving an error: 08:01:56 (13016) ERROR TestRunnerChildProcessAdapter Child process exited with non-zero exit code 1. Last 10 message from the child process were: 08:01:56 (13016) ERROR InitialTestExecutor One or more tests resulted in an error: Stryker configmodule.exports = function(config){
config.set({
mutate: [
"src/pages/poi-email/*.js"
],
testRunner: "mocha",
mutator: "javascript",
transpilers: ["babel"],
reporter: ["clear-text", "progress"],
packageManager: "npm",
coverageAnalysis: "off",
babelrcFile: ".babelrc"
});
} Stryker environment
|
From your test command I conclude that you're not using babel for your mocha tests, is this correct? Seeing as this is your test command: Or am I missing something? A mocha.opts file perhaps? Could you try this configuration: module.exports = function(config){
config.set({
mutate:[
"src/pages/poi/*.js"
],
testRunner: "mocha",
testFramework: "mocha",
mutator: "javascript",
reporter: ["html", "clear-text", "progress"],
coverageAnalysis: "off",
mochaOptions: {
files: [ './test/**/*-tests.js' ]
}
});
} EDIT: Also run it with the same environment variables. Add this to your package.json: "scripts": {
"stryker": "cross-env NODE_ENV=test stryker run"
} And run using |
I tried the configuration @nicojs suggested but I get a syntax error on the import. This happens when we don't include the babel transpiler. We do have a mocha.opts file in which our mocha-hook.js file is required. babel-register is required in the hook.js file, which should also disable our css imports. Could there be an issue where the mocha.opts file is not being used correctly? |
Yes, this is most definitely it. It is not used by default. Mocha has no clean way of providing the mocha.opts file, instead we had to recreate the functionality. See https://github.com/stryker-mutator/stryker/tree/master/packages/stryker-mocha-runner#configuring I think our implementation doesn't support local requires. Could you try this: module.exports = function(config){
config.set({
mutate:[
"src/pages/poi/*.js"
],
testRunner: "mocha",
testFramework: "mocha",
mutator: "javascript",
reporter: ["html", "clear-text", "progress"],
coverageAnalysis: "off",
mochaOptions: {
files: [ './test/**/*-tests.js' ],
opts: 'mocha.opts',
require: [require.resolve('./mocha-hook.js')]
}
});
} That should do the trick. |
Alright, I think we're almost there. I am getting a different error: 11:17:04 (7868) ERROR TestRunnerChildProcessAdapter Child process exited with non-zero exit code 1. Last 10 message from the child process were: 11:17:04 (7868) ERROR InitialTestExecutor One or more tests resulted in an error: I am using chai, enzyme, and sinon along with mocha if that makes a difference. I also need to add our dom.js file to the require tag under mochaOptions, but I'm unsure of the usage 'require.resolve'. Will I just need to add another require to the array and put in the corresponding path or does resolve take multiple strings as arguments? |
I'm not sure who is responsible for adding
mochaOptions: {
files: [ './test/**/*-tests.js' ],
opts: 'mocha.opts',
require: [require.resolve('./mocha-hook.js'), require.resolve('./dom.js')]
} If this setup works we need to fix it so that we use your mocha.opts file by default as well as make sure relative imports work as expected. But lets first get it working for you. |
Unfortunately adding the dom.js didn't resolve any issues. I'm still getting the same error for mocha.describe. I would think the "stryker-mocha-framework" and "stryker-mocha-runner" would take care of it. |
Yes, they should make sure Hmm ok, time to pull out the big guns. Could you open up MochaTestRunner.prototype.additionalRequires = function () {
var _this = this;
if (this.mochaRunnerOptions.require) {
var stuffToRequire = this.mochaRunnerOptions.require
.map(function (theModule) { return theModule.startsWith('.') ? path.resolve(theModule) : theModule; });
stuffToRequire.forEach(function (theModule) { return _this.log.info("Importing " + theModule); });
stuffToRequire
.forEach(LibWrapper_1.default.require);
}
else {
this.log.info('Nothing to require');
}
}; That should make local requires possible (and add some logging). If you now remove the entire If that doesn't work, would you mind creating a small reproduction repository? The smaller the better. If we could take a look, I'm sure we could figure it out. |
I'll see to creating a small repository that reproduces the problem (today). Unfortunately the replacement of the function did not help, I'm still getting the same error. I also added the ui tag and gave it 'bdd', but that didn't seem to help either. I also wanted some clarification on location of the config file. The readme says that it is expected to be the current working directory, but then goes on to say: "As you can see, the config file is not a simple JSON file. It should be a node module." I have my config file in the root directory, just want to make sure this isn't an issue. EDIT: I jut realized I never gave the whole error message last time. Here it is below: 08:12:35 (11112) ERROR TestRunnerChildProcessAdapter Child process exited with non-zero exit code 1. Last 10 message from the child process were: 08:12:35 (11112) ERROR InitialTestExecutor One or more tests resulted in an error: |
No, no issue there.
Awesome! I'm sure we'll be able to fix this issue once we can reproduce it 👍 |
So I figured out what was causing describe not be recognized as a function. I got the idea here. I simply had to remove my import statement for mocha and it started working. The weird thing is when I tried to reproduce the error on my computer with the import statements it would still work and give me no error. It may be some anomaly with the environment, there's a lot of code and environment setup that was done by other people. Thanks so much to both of you for your help. |
@prsn670 Awesome you made it work! Have fun improving your test! Thanks for closing, but i would like to keep this issue open. I want to fix 3 things:
|
@nicojs Shall we create an issue for the problems you mention? |
I was thinking to use this issue for them. Doesn't matter really. |
I have renamed the issue. This comment by Nico contains a list of things to do for this issue. |
Working on it |
Summary
Hello all, I was hoping somebody could let me know what I'm doing wrong here. I keep getting a syntax error on CSS files. We're using Stryker version 0.14.1. We are also using react/redux with the mocha test framework. We are not using webpack. I'm unsure if it is some configuration error, version issue, or something completely different. The error is as follows:
[2018-07-26 13:02:05.874] [ERROR] InitialTestExecutor - One or more tests resulted in an error:
SyntaxError: Unexpected token .
C:\code_base\poi\node_modules\form\lib\util\block.css:1
(function (exports, require, module, __filename, __dirname) { .a-form-v3-10-0-block {
Stryker config
Stryker environment
Your Environment
The text was updated successfully, but these errors were encountered: