-
-
Notifications
You must be signed in to change notification settings - Fork 133
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(jest mock): Add stub for static content
Fix bug for unit testing component dom that includes static content like a sass file. Include jest-tranform-stub. Resolves aurelia/testing#67
- Loading branch information
1 parent
116d6d7
commit f7cb875
Showing
2 changed files
with
46 additions
and
76 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,10 @@ | |
const ProjectItem = require('../../../../../project-item').ProjectItem; | ||
|
||
module.exports = function(project) { | ||
let configureJasmine = require('./jasmine'); | ||
const isUsingBabel = project.model.transpiler.id === 'babel'; | ||
const isUsingTS = project.model.transpiler.id === 'typescript'; | ||
const configureJasmine = require('./jasmine'); | ||
|
||
configureJasmine(project); | ||
|
||
project.addToTasks( | ||
|
@@ -15,94 +18,60 @@ module.exports = function(project) { | |
).addToDevDependencies( | ||
'jest', | ||
'jest-cli', | ||
'jest-transform-stub', | ||
'aurelia-loader-nodejs', | ||
'aurelia-pal-nodejs' | ||
).addNPMScript('test', 'au jest'); | ||
|
||
if (project.model.transpiler.id === 'babel') { | ||
const transform = { | ||
'^.+\\.(css|less|sass|scss|jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$': 'jest-transform-stub' | ||
}; | ||
|
||
const moduleFileExtensions = ['js', 'json']; | ||
const setupFiles = []; | ||
const collectCoverageFrom = [ '!**/node_modules/**', '!**/test/**' ]; | ||
let testRegex = '\\.spec\\.'; | ||
|
||
if (isUsingBabel) { | ||
project.addToDevDependencies( | ||
'babel-jest', | ||
'[email protected]' | ||
); | ||
|
||
project.package.jest = { | ||
moduleNameMapper: { | ||
// avoid aurelia-bindings v1+v2 conflict | ||
'^aurelia-binding$': '<rootDir>/node_modules/aurelia-binding' | ||
}, | ||
modulePaths: [ | ||
'<rootDir>/src', | ||
'<rootDir>/node_modules' | ||
], | ||
moduleFileExtensions: [ | ||
'js', | ||
'json' | ||
], | ||
transform: { | ||
'^.+\\.js$': 'babel-jest' | ||
}, | ||
testRegex: '\\.spec\\.js$', | ||
setupFiles: [ | ||
'<rootDir>/test/jest-pretest.js' | ||
], | ||
testEnvironment: 'node', | ||
collectCoverage: true, | ||
collectCoverageFrom: [ | ||
'src/**/*.js', | ||
'!**/*.spec.js', | ||
'!**/node_modules/**', | ||
'!**/test/**' | ||
], | ||
coverageDirectory: '<rootDir>/test/coverage-jest', | ||
coverageReporters: [ | ||
'json', | ||
'lcov', | ||
'text', | ||
'html' | ||
] | ||
}; | ||
} else if (project.model.transpiler.id === 'typescript') { | ||
transform['^.+\\.js$'] = 'babel-jest'; | ||
testRegex += 'js$'; | ||
setupFiles.push('<rootDir>/test/jest-pretest.js'); | ||
collectCoverageFrom.push( 'src/**/*.js', '!**/*.spec.js'); | ||
} else if (isUsingTS) { | ||
project.addToDevDependencies( | ||
'ts-jest', | ||
'@types/jest' | ||
); | ||
|
||
project.package.jest = { | ||
moduleNameMapper: { | ||
// avoid aurelia-bindings v1+v2 conflict | ||
'^aurelia-binding$': '<rootDir>/node_modules/aurelia-binding' | ||
}, | ||
modulePaths: [ | ||
'<rootDir>/src', | ||
'<rootDir>/node_modules' | ||
], | ||
moduleFileExtensions: [ | ||
'js', | ||
'json', | ||
'ts' | ||
], | ||
transform: { | ||
'^.+\\.ts$': 'ts-jest' | ||
}, | ||
testRegex: '\\.spec\\.(ts|js)$', | ||
setupFiles: [ | ||
'<rootDir>/test/jest-pretest.ts' | ||
], | ||
testEnvironment: 'node', | ||
collectCoverage: true, | ||
collectCoverageFrom: [ | ||
'src/**/*.{js,ts}', | ||
'!**/*.spec.{js,ts}', | ||
'!**/node_modules/**', | ||
'!**/test/**' | ||
], | ||
coverageDirectory: '<rootDir>/test/coverage-jest', | ||
coverageReporters: [ | ||
'json', | ||
'lcov', | ||
'text', | ||
'html' | ||
] | ||
}; | ||
transform['^.+\\.ts$'] = 'ts-jest'; | ||
moduleFileExtensions.push('ts'); | ||
testRegex += '(ts|js)$'; | ||
setupFiles.push('<rootDir>/test/jest-pretest.ts'); | ||
collectCoverageFrom.push( 'src/**/*.{js,ts}', '!**/*.spec.{js,ts}'); | ||
} | ||
|
||
project.package.jest = { | ||
moduleNameMapper: { | ||
// avoid aurelia-bindings v1+v2 conflict | ||
'^aurelia-binding$': '<rootDir>/node_modules/aurelia-binding' | ||
}, | ||
modulePaths: [ | ||
'<rootDir>/src', | ||
'<rootDir>/node_modules' | ||
], | ||
moduleFileExtensions, | ||
transform, | ||
testRegex, | ||
setupFiles, | ||
testEnvironment: 'node', | ||
collectCoverage: true, | ||
collectCoverageFrom, | ||
coverageDirectory: '<rootDir>/test/coverage-jest', | ||
coverageReporters: [ 'json', 'lcov', 'text', 'html'] | ||
}; | ||
}; |
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