Skip to content

Commit

Permalink
Merge pull request #129 from odecee/feature/update-testUnit-to-multi-…
Browse files Browse the repository at this point in the history
…test-framework

feat(testUnit): add test-framework support and use nyc for Node projects
  • Loading branch information
uglow committed Sep 4, 2017
2 parents 01e4432 + f5bf75e commit ca31a52
Show file tree
Hide file tree
Showing 34 changed files with 256 additions and 189 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -5,3 +5,5 @@ log/
.idea
website/
*.log
devlog.md
.nyc_output/
25 changes: 25 additions & 0 deletions .nycrc
@@ -0,0 +1,25 @@
{
"check-coverage": true,
"per-file": false,
"statements": 75,
"branches": 65,
"functions": 75,
"lines": 75,
"include": [
"lib/**/*.js"
],
"exclude": [
"test/**/*.spec.js",
"lib/**/templates/*"
],
"reporter": [
"lcovonly",
"html",
"text",
"cobertura",
"json"
],
"cache": true,
"all": true,
"report-dir": "./reports/coverage/"
}
34 changes: 0 additions & 34 deletions config/testUnit/istanbul.js

This file was deleted.

3 changes: 2 additions & 1 deletion config/testUnit/mocha.opts
@@ -1,5 +1,6 @@
test/spec/unit/**/*.spec.js
--reporter list
--reporter mocha-multi-reporters
--reporter-options configFile=config/testUnit/reporters.json
--no-timeouts
--ui bdd
--MAX_LOG=false
Expand Down
6 changes: 6 additions & 0 deletions config/testUnit/reporters.json
@@ -0,0 +1,6 @@
{
"reporterEnabled": "list, mocha-junit-reporter",
"mochaJunitReporterReporterOptions": {
"mochaFile": "reports/junit.xml"
}
}
14 changes: 0 additions & 14 deletions config/testUnit/thresholds.json

This file was deleted.

11 changes: 6 additions & 5 deletions confit.yml
@@ -1,14 +1,14 @@
generator-confit:
app:
_version: 7e07568e0cef2abb035b03a5900830ab1f3a02ea
_version: 462ecd915fd9db1aef6a37c2b5ce8b58b80c18ba
buildProfile: Latest
copyrightOwner: Brett Uglow
license: Apache-2.0
projectType: node
publicRepository: true
repositoryType: GitHub
paths:
_version: 7f33e41600b34cd6867478d8f2b3d6b2bbd42508
_version: 780b129e0c7e5cab7e29c4f185bcf78524593a33
config:
configDir: config/
input:
Expand All @@ -18,19 +18,20 @@ generator-confit:
prodDir: dist/
reportDir: reports/
buildJS:
_version: df428a706d926204228c5d9ebdbd7b49908926d9
_version: ead8ce4280b07d696aff499a5fca1a933727582f
framework: []
frameworkScripts: []
outputFormat: ES6
sourceFormat: ES6
entryPoint:
_version: de20402bf85c703080ef6daf21e35325a3b9d604
_version: 39082c3df887fbc08744dfd088c25465e7a2e3a4
entryPoints:
main:
- lib/generators/app/index.js
testUnit:
_version: 4472a6d59b434226f463992d3c1914c77a6a115d
_version: 30eee42a88ee42cce4f1ae48fe0cbe81647d189a
testDependencies: []
testFramework: mocha
verify:
_version: 30ae86c5022840a01fc08833e238a82c683fa1c7
jsCodingStandard: Google
Expand Down
34 changes: 13 additions & 21 deletions lib/buildTool/npm/npmResources.yml
Expand Up @@ -238,13 +238,14 @@ release:
- condition: <%- app.repositoryType === 'GitHub' && release.checkCodeCoverage %>
tasks:
- name: upload-coverage
tasks: ['cat <%- paths.output.reportDir + resources.testUnit.coverageReportSubDir %>lcov/lcov.info | ./node_modules/coveralls/bin/coveralls.js']
tasks: ['cat <%- paths.output.reportDir + resources.testUnit.coverageReportSubDir %><%- app.projectType === "node" ? "" : "lcov/" %>lcov.info | coveralls']
description: Uploads code-coverage metrics to Coveralls.io
features:
- Setup - https://coveralls.zendesk.com/hc/en-us/articles/201347419-Coveralls-currently-supports
- Define an environment variable called COVERALLS_REPO_TOKEN in your build environment with the repo token from https://coveralls.io/github/<repo-name>/settings
- In your CI configuration (e.g. `travis.yml`), call `npm run upload-coverage` if the build is successful.


sampleApp:

toolModules:
Expand Down Expand Up @@ -280,19 +281,22 @@ testUnit:
packages:
- <<: *pkg_chokidar-cli
- <<: *pkg_mocha
- <<: *pkg_istanbul
- <<: *pkg_mocha-multi-reporters
- <<: *pkg_mocha-junit-reporter
- <<: *pkg_nyc

templateFiles:
- src: istanbul.js
dest: <%- paths.config.configDir + resources.testUnit.configSubDir %>istanbul.js
- src: nycrc.json.tpl
dest: .nycrc
overwrite: true

- src: mocha.opts
dest: <%- paths.config.configDir + resources.testUnit.configSubDir %>mocha.opts
overwrite: true

- src: thresholds.json
dest: <%- paths.config.configDir + resources.testUnit.configSubDir %>thresholds.json
- src: reporters.json
dest: <%- paths.config.configDir + resources.testUnit.configSubDir %>reporters.json
overwrite: true

tasks:
- name: test
Expand All @@ -301,34 +305,22 @@ testUnit:
features: []

- name: test:unit
tasks:
- >
<%
var jsExtensions = resources.buildJS.sourceFormat[buildJS.sourceFormat].ext;
var testWatchPaths = [paths.input.srcDir + '**/*.', paths.input.unitTestDir + '**/*.'];
var completeTestPaths = [];
testWatchPaths.forEach(function(path) {
jsExtensions.forEach(function(ext) {
completeTestPaths.push(path + ext);
});
});
-%>chokidar '<%- completeTestPaths.join('\' \'') -%>' -c 'npm run test:unit:once' --initial --silent<% -%>
tasks: ['cross-env NODE_ENV=test nyc mocha --opts <%- paths.config.configDir + resources.testUnit.configSubDir %>mocha.opts -w']
description: Run unit tests whenever JS source or tests change
features:
- Uses Mocha
- Code coverage
- Runs continuously (best to run in a separate window)

- name: test:unit:once
# Note the use of "_mocha" instead of "mocha". "_mocha" is the real executable, "mocha" is a wrapper.
tasks: ['cross-env NODE_ENV=test istanbul cover --config <%- paths.config.configDir + resources.testUnit.configSubDir %>istanbul.js _mocha -- --opts <%- paths.config.configDir + resources.testUnit.configSubDir %>mocha.opts']
tasks: ['cross-env NODE_ENV=test nyc mocha --opts <%- paths.config.configDir + resources.testUnit.configSubDir %>mocha.opts']
description: Run unit tests once
features:
- Uses Mocha
- Code coverage

- name: test:check-coverage
tasks: ['cross-env NODE_ENV=test istanbul check-coverage <%- paths.output.reportDir + resources.testUnit.coverageReportSubDir %>coverage.json --config <%- paths.config.configDir + resources.testUnit.configSubDir %>istanbul.js']
tasks: ['nyc check-coverage']
description:
features:

Expand Down
34 changes: 0 additions & 34 deletions lib/buildTool/npm/testUnit/templates/istanbul.js

This file was deleted.

3 changes: 2 additions & 1 deletion lib/buildTool/npm/testUnit/templates/mocha.opts
@@ -1,4 +1,5 @@
<%= paths.input.unitTestDir %>**/*.spec.js
--reporter list
--reporter mocha-multi-reporters
--reporter-options configFile=<%- paths.config.configDir + resources.testUnit.configSubDir %>reporters.json
--no-timeouts
--ui bdd
24 changes: 24 additions & 0 deletions lib/buildTool/npm/testUnit/templates/nycrc.json.tpl
@@ -0,0 +1,24 @@
{
"check-coverage": true,
"per-file": true,
"lines": 40,
"statements": 40,
"functions": 20,
"branches": 50,
"include": [
"<%- paths.input.srcDir %>**/*.js"
],
"exclude": [
"<%- paths.input.unitTestDir %>**/*.spec.js"
],
"reporter": [
"lcovonly",
"html",
"text",
"cobertura",
"json"
],
"cache": true,
"all": true,
"report-dir": "./<%- paths.output.reportDir + resources.testUnit.coverageReportSubDir %>"
}
6 changes: 6 additions & 0 deletions lib/buildTool/npm/testUnit/templates/reporters.json
@@ -0,0 +1,6 @@
{
"reporterEnabled": "list, mocha-junit-reporter",
"mochaJunitReporterReporterOptions": {
"mochaFile": "<%- paths.output.reportDir %>junit.xml"
}
}
14 changes: 0 additions & 14 deletions lib/buildTool/npm/testUnit/templates/thresholds.json

This file was deleted.

21 changes: 21 additions & 0 deletions lib/buildTool/webpack/testUnit/templates/helpers/karmaHelper.js
@@ -0,0 +1,21 @@
exports.getPlugins = (testFramework) => {
const plugins = [
'karma-chrome-launcher',
'karma-coverage',
'karma-remap-coverage',
'karma-sourcemap-loader',
'karma-webpack'
];

const frameworkPlugins = {
mocha: [
...plugins,
'karma-mocha',
'karma-chai',
'karma-sinon'
],
jasmine: [...plugins, 'karma-jasmine']
};

return frameworkPlugins[testFramework];
}
12 changes: 8 additions & 4 deletions lib/core/packages.yml
Expand Up @@ -307,10 +307,6 @@ $packages:
name: husky
version: 0.13.3

- &pkg_istanbul # Seems to some work towards an alpha version, but hundreds of open issues and tens of pull requests
name: istanbul
version: 0.4.5

- &pkg_istanbul-instrumenter-loader
name: istanbul-instrumenter-loader
version: 0.2.0
Expand Down Expand Up @@ -379,6 +375,10 @@ $packages:
name: mochawesome
version: 2.3.0

- &pkg_mocha-multi-reporters
name: mocha-multi-reporters
version: 1.1.5

- &pkg_mocha-junit-reporter
name: mocha-junit-reporter
version: 1.13.0
Expand All @@ -396,6 +396,10 @@ $packages:
name: npm-run-all
version: 4.0.2

- &pkg_nyc
name: nyc
version: 11.1.0

- &pkg_object-assign # Polyfill for Object.assign (used by React)
name: object-assign
version: 4.1.1
Expand Down
1 change: 0 additions & 1 deletion lib/generators/buildCSS/index.js
Expand Up @@ -24,7 +24,6 @@ module.exports = confitGen.create({
},
];


return this.prompt(prompts).then(function(props) {
this.answers = this.generateObjFromAnswers(props);
}.bind(this));
Expand Down

0 comments on commit ca31a52

Please sign in to comment.