-
Notifications
You must be signed in to change notification settings - Fork 250
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
fix(mocha framework): Select tests based on name #413
Merged
Merged
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
512e387
fix(mocha framework): Select tests based on name
nicojs e976497
Merge branch 'master' into fix-mocha-test-selection
nicojs 3d3ecb0
refactor(coverage): Use transpiler pipeline
nicojs edda7ef
Implement changes based on code review.
nicojs 5fb1764
Merge branch 'master' into fix-mocha-test-selection
nicojs File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export default interface TestSelection { | ||
id: number; | ||
name: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export {default as TestFramework} from './src/test_framework/TestFramework'; | ||
export {default as TestSelection} from './src/test_framework/TestSelection'; | ||
export {default as TestFrameworkFactory} from './src/test_framework/TestFrameworkFactory'; | ||
export {default as TestFrameworkSettings} from './src/test_framework/TestFrameworkSettings'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,123 +1,40 @@ | ||
{ | ||
"version": "0.2.0", | ||
"configurations": [ | ||
{ | ||
"name": "Run unit tests", | ||
"type": "node", | ||
"request": "launch", | ||
"program": "${workspaceRoot}/node_modules/grunt/bin/grunt", | ||
// "preLaunchTask": "build", | ||
"stopOnEntry": false, | ||
"args": [ | ||
"mochaTest:unit" | ||
], | ||
"cwd": "${workspaceRoot}/.", | ||
"runtimeExecutable": null, | ||
"runtimeArgs": [ | ||
"--nolazy" | ||
], | ||
"env": { | ||
"NODE_ENV": "development" | ||
// Use IntelliSense to learn about possible attributes. | ||
// Hover to view descriptions of existing attributes. | ||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 | ||
"version": "0.2.0", | ||
"configurations": [ | ||
{ | ||
"type": "node", | ||
"request": "launch", | ||
"name": "Unit tests", | ||
"program": "${workspaceFolder}/../../node_modules/mocha/bin/_mocha", | ||
"args": [ | ||
"-u", | ||
"tdd", | ||
"--timeout", | ||
"999999", | ||
"--colors", | ||
"${workspaceFolder}/test/helpers/**/*.js", | ||
"${workspaceFolder}/test/unit/**/*.js" | ||
], | ||
"internalConsoleOptions": "openOnSessionStart" | ||
}, | ||
"externalConsole": false, | ||
"sourceMaps": true, | ||
"outDir": "${workspaceRoot}" | ||
}, | ||
{ | ||
"name": "Run integration tests", | ||
"type": "node", | ||
"request": "launch", | ||
"program": "${workspaceRoot}/node_modules/grunt-cli/bin/grunt", | ||
// "preLa4unchTask": "ts", | ||
"stopOnEntry": false, | ||
"args": [ | ||
"mochaTest:integration" | ||
], | ||
"cwd": "${workspaceRoot}/.", | ||
"runtimeExecutable": null, | ||
"runtimeArgs": [ | ||
"--nolazy" | ||
], | ||
"env": { | ||
"NODE_ENV": "development" | ||
}, | ||
"externalConsole": false, | ||
"sourceMaps": true, | ||
"outDir": "${workspaceRoot}" | ||
}, | ||
{ | ||
"name": "Run stryker example", | ||
"type": "node", | ||
"request": "launch", | ||
"program": "${workspaceRoot}/bin/stryker", | ||
"preLaunchTask": "build", | ||
"stopOnEntry": false, | ||
"args": [ | ||
"--configFile", | ||
"testResources/sampleProject/stryker.conf.js", | ||
"--logLevel", | ||
"trace", | ||
"--testFramework", | ||
"jasmine" | ||
], | ||
"cwd": "${workspaceRoot}", | ||
"runtimeExecutable": null, | ||
"runtimeArgs": [ | ||
"--nolazy" | ||
], | ||
"env": { | ||
"NODE_ENV": "development" | ||
}, | ||
"externalConsole": false, | ||
"sourceMaps": true, | ||
"outDir": "${workspaceRoot}" | ||
}, | ||
{ | ||
"name": "Run own dog food", | ||
"type": "node", | ||
"request": "launch", | ||
"program": "${workspaceRoot}/bin/stryker", | ||
"preLaunchTask": "build", | ||
"stopOnEntry": false, | ||
"args": [ | ||
"--configFile", | ||
"stryker.conf.js", | ||
"--logLevel", | ||
"info" | ||
], | ||
"cwd": "${workspaceRoot}", | ||
"runtimeExecutable": null, | ||
"runtimeArgs": [ | ||
"--nolazy" | ||
], | ||
"env": { | ||
"NODE_ENV": "development" | ||
}, | ||
"externalConsole": false, | ||
"sourceMaps": true, | ||
"outDir": "${workspaceRoot}" | ||
}, | ||
{ | ||
"name": "Run stryker help", | ||
"type": "node", | ||
"request": "launch", | ||
"program": "${workspaceRoot}/src/Stryker.js", | ||
"preLaunchTask": "build", | ||
"stopOnEntry": false, | ||
"args": [ | ||
"--help" | ||
], | ||
"cwd": "${workspaceRoot}/.", | ||
"runtimeExecutable": null, | ||
"runtimeArgs": [ | ||
"--nolazy" | ||
], | ||
"env": { | ||
"NODE_ENV": "development" | ||
}, | ||
"externalConsole": false, | ||
"sourceMaps": true, | ||
"outDir": "${workspaceRoot}" | ||
} | ||
] | ||
{ | ||
"type": "node", | ||
"request": "launch", | ||
"name": "Integration tests", | ||
"program": "${workspaceFolder}/../../node_modules/mocha/bin/_mocha", | ||
"args": [ | ||
"-u", | ||
"tdd", | ||
"--timeout", | ||
"999999", | ||
"--colors", | ||
"${workspaceFolder}/test/helpers/**/*.js", | ||
"${workspaceFolder}/test/integration/**/*.js" | ||
], | ||
"internalConsoleOptions": "openOnSessionStart" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
// See https://go.microsoft.com/fwlink/?LinkId=733558 | ||
// for the documentation about the tasks.json format | ||
"version": "2.0.0", | ||
"tasks": [ | ||
{ | ||
"type": "typescript", | ||
"tsconfig": "tsconfig.json", | ||
"option": "watch", | ||
"problemMatcher": [ | ||
"$tsc-watch" | ||
], | ||
"group": { | ||
"kind": "build", | ||
"isDefault": true | ||
} | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
packages/stryker-jasmine/test/integration/nestedSuiteSpec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
import * as path from 'path'; | ||
import * as execa from 'execa'; | ||
import { expect } from 'chai'; | ||
import { TestSelection } from 'stryker-api/test_framework'; | ||
import JasmineTestFramework from '../../src/JasmineTestFramework'; | ||
import * as fs from 'fs'; | ||
import * as rimraf from 'rimraf'; | ||
|
||
interface JasmineTest { | ||
id: string; | ||
description: string; | ||
fullName: string; | ||
failedExpectations: any[]; | ||
passedExpectations: any[]; | ||
status: string; | ||
} | ||
|
||
describe('Selecting tests with nested suites', function () { | ||
|
||
this.timeout(10000); | ||
let sut: JasmineTestFramework; | ||
let testSelections: TestSelection[]; | ||
const jsonReporterFile = path.resolve(__dirname, '..', '..', 'testResources', 'json-reporter.js'); | ||
const nestedSuiteFile = path.resolve(__dirname, '..', '..', 'testResources', 'nested-suite.js'); | ||
const selectTestFile = path.join(__dirname, '..', '..', 'testResources', '__filterSpecs.js'); | ||
|
||
beforeEach(() => { | ||
sut = new JasmineTestFramework(); | ||
testSelections = [ | ||
{ id: 0, name: 'outer test 1' }, | ||
{ id: 1, name: 'outer test 2' }, | ||
{ id: 2, name: 'outer inner test 3' } | ||
]; | ||
}); | ||
|
||
afterEach(() => { | ||
rimraf.sync(selectTestFile); | ||
}); | ||
|
||
it('should run all tests in expected order when running all tests', () => { | ||
const result = execJasmine(nestedSuiteFile); | ||
expect(result.map(test => test.fullName)).deep.eq(['outer test 1', 'outer inner test 2', 'outer test 3']); | ||
}); | ||
|
||
it('should only run test 1 if filtered on index 0', () => { | ||
filter([0]); | ||
const result = execJasmine(selectTestFile, nestedSuiteFile); | ||
expect(result).lengthOf(3); | ||
expect(result[0].status).eq('passed'); | ||
expect(result[1].status).eq('disabled'); | ||
expect(result[2].status).eq('disabled'); | ||
expect(result[0].fullName).eq('outer test 1'); | ||
}); | ||
|
||
it('should only run test 2 if filtered on index 1', () => { | ||
filter([1]); | ||
const result = execJasmine(selectTestFile, nestedSuiteFile); | ||
expect(result).lengthOf(3); | ||
expect(result[0].status).eq('disabled'); | ||
expect(result[1].status).eq('passed'); | ||
expect(result[2].status).eq('disabled'); | ||
expect(result[1].fullName).eq('outer inner test 2'); | ||
}); | ||
|
||
it('should only run test 3 if filtered on index 2', () => { | ||
filter([2]); | ||
const result = execJasmine(selectTestFile, nestedSuiteFile); | ||
expect(result).lengthOf(3); | ||
expect(result[0].status).eq('disabled'); | ||
expect(result[1].status).eq('disabled'); | ||
expect(result[2].status).eq('passed'); | ||
expect(result[2].fullName).eq('outer test 3'); | ||
}); | ||
|
||
function filter(testIds: number[]) { | ||
const selections = testIds.map(id => testSelections[id]); | ||
const filterFn = `(function (window) {${sut.filter(selections)}})(global);`; | ||
fs.writeFileSync(selectTestFile, filterFn, 'utf8'); | ||
} | ||
|
||
function execJasmine(...files: string[]): JasmineTest[] { | ||
const execResult = execa.sync('jasmine', [jsonReporterFile, ...files]); | ||
return JSON.parse(execResult.stdout); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you ever pass anything other than a single number? If you don't won't it be easier to just allow one test id?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. I've added a test where we filter 2 tests just to make sure it works.