Skip to content

Commit

Permalink
fix(sandbox): exec build command before symlink
Browse files Browse the repository at this point in the history
Execute the `buildCommand` before the node_modules are symlinked inside the sandbox. This way, there is more chance that the node_modules can be resolved correctly.
  • Loading branch information
nicojs committed Jul 10, 2020
1 parent 574e86f commit bd25cd6
Show file tree
Hide file tree
Showing 11 changed files with 69 additions and 49 deletions.
4 changes: 3 additions & 1 deletion e2e/tasks/run-e2e-tests.ts
Expand Up @@ -17,7 +17,9 @@ const mutationSwitchingTempWhiteList = [
'vue-javascript',
'karma-webpack-with-ts',
'mocha-mocha',
'mocha-ts-node'
'mocha-ts-node',
'babel-transpiling',
'typescript-transpiling'
]

function runE2eTests() {
Expand Down
3 changes: 3 additions & 0 deletions e2e/test/babel-transpiling/.mocharc.json
@@ -0,0 +1,3 @@
{
"spec": "dist/test/**.js"
}
6 changes: 5 additions & 1 deletion e2e/test/babel-transpiling/package.json
Expand Up @@ -5,9 +5,13 @@
"description": "A module to test stryker-babel with stryker-javascript-mutator",
"main": "index.js",
"scripts": {
"prebuild": "rimraf dist",
"tmp": "echo %cd%",
"build": "babel -d dist --only \"src/**/*.js\" --only \"test/**/*.js\" .",
"pretest": "rimraf \"reports\"",
"test": "stryker run",
"posttest": "mocha --require ../../tasks/ts-node-register.js verify/*.ts"
"test:unit": "mocha",
"posttest": "mocha --no-config --require ../../tasks/ts-node-register.js verify/*.ts"
},
"keywords": [],
"author": "",
Expand Down
17 changes: 7 additions & 10 deletions e2e/test/babel-transpiling/stryker.conf.js
Expand Up @@ -5,15 +5,12 @@ module.exports = {
testFramework: 'mocha',
testRunner: 'mocha',
coverageAnalysis: 'off',
mutator: {
name: 'javascript',
plugins: [['pipelineOperator', { proposal: 'minimal' }]]
},
transpilers: [
'babel'
],
buildCommand: 'npm run build',
timeoutMS: 60000,
reporters: ['clear-text', 'html', 'event-recorder'],
maxConcurrentTestRunners: 2,
logLevel: 'info'
reporters: ['clear-text', 'html', 'event-recorder', 'progress'],
concurrency: 1,
logLevel: 'info',
plugins: [
'@stryker-mutator/mocha-runner'
]
};
14 changes: 12 additions & 2 deletions e2e/test/typescript-transpiling/package.json
Expand Up @@ -5,9 +5,19 @@
"description": "A module to perform an integration test",
"main": "index.js",
"scripts": {
"clean": "rimraf dist",
"prebuild": "npm run clean",
"build": "tsc",
"pretest:unit": "npm run build",
"test:unit": "mocha",
"pretest": "rimraf \"reports\"",
"test": "stryker run stryker.conf.js",
"posttest": "mocha --require ../../tasks/ts-node-register.js verify/*.ts"
"test": "stryker run",
"posttest": "mocha --require ../../tasks/ts-node-register.js --no-package verify/*.ts"
},
"mocha": {
"spec": [
"dist/test/**/*.js"
]
},
"author": "",
"license": "ISC"
Expand Down
21 changes: 0 additions & 21 deletions e2e/test/typescript-transpiling/stryker.conf.js

This file was deleted.

18 changes: 18 additions & 0 deletions e2e/test/typescript-transpiling/stryker.conf.json
@@ -0,0 +1,18 @@
{
"$schema": "../../node_modules/@stryker-mutator/core/schema/stryker-schema.json",
"mutate": [
"src/*.ts"
],
"packageManager": "npm",
"testRunner": "mocha",
"concurrency": 1,
"coverageAnalysis": "perTest",
"reporters": ["event-recorder", "html", "progress", "clear-text"],
"checkers": ["typescript"],
"tsconfigFile": "tsconfig.json",
"buildCommand": "npm run build",
"plugins": [
"@stryker-mutator/mocha-runner",
"@stryker-mutator/typescript-checker"
]
}
19 changes: 9 additions & 10 deletions e2e/test/typescript-transpiling/tsconfig.json
@@ -1,15 +1,14 @@
{
"compilerOptions": {
"lib": [
"es5",
"es2015.promise",
"es2015.core"
"target": "es2017",
"module": "commonjs",
"outDir": "dist",
"types": [
"mocha"
]
},
"files": [
"src/Add.ts",
"src/Circle.ts",
"test/AddSpec.ts",
"test/CircleSpec.ts"
"include": [
"src",
"test",
]
}
}
7 changes: 4 additions & 3 deletions e2e/test/typescript-transpiling/verify/verify.ts
Expand Up @@ -7,9 +7,10 @@ describe('Verify stryker has ran correctly', () => {
metrics: produceMetrics({
killed: 16,
mutationScore: 64,
mutationScoreBasedOnCoveredCode: 64,
survived: 9,
totalCovered: 25,
mutationScoreBasedOnCoveredCode: 94.12,
survived: 1,
noCoverage: 8,
totalCovered: 17,
totalDetected: 16,
totalMutants: 25,
totalUndetected: 9,
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/sandbox/sandbox.ts
Expand Up @@ -47,8 +47,8 @@ export class Sandbox {

private async initialize(): Promise<void> {
await this.fillSandbox();
await this.symlinkNodeModulesIfNeeded();
await this.runBuildCommand();
await this.symlinkNodeModulesIfNeeded();
}

public static create: SandboxFactory = Object.assign(
Expand Down
7 changes: 7 additions & 0 deletions packages/core/test/unit/sandbox/sandbox.spec.ts
Expand Up @@ -146,6 +146,13 @@ describe(Sandbox.name, () => {
await createSut();
expect(execaStub).not.called;
});

it('should execute the buildCommand before the node_modules are symlinked', async () => {
// It is important to first run the buildCommand, otherwise the build dependencies are not correctly resolved
testInjector.options.buildCommand = 'npm run build';
await createSut();
expect(execaStub).calledBefore(symlinkJunctionStub);
});
});

describe('get sandboxFileNames()', () => {
Expand Down

0 comments on commit bd25cd6

Please sign in to comment.