Skip to content

Commit

Permalink
separate integration and unit tests, use codecov flags
Browse files Browse the repository at this point in the history
  • Loading branch information
sokra committed Oct 19, 2017
1 parent 168f923 commit 0c104a6
Show file tree
Hide file tree
Showing 54 changed files with 183 additions and 315 deletions.
3 changes: 3 additions & 0 deletions .istanbul.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
instrumentation:
excludes:
- "**/*.runtime.js"
13 changes: 8 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,19 @@ matrix:
env: NO_WATCH_TESTS=1 JOB_PART=lint
- os: linux
node_js: "8"
env: NO_WATCH_TESTS=1 JOB_PART=test
env: NO_WATCH_TESTS=1 JOB_PART=integration
- os: linux
node_js: "8"
env: NO_WATCH_TESTS=1 JOB_PART=unit
- os: linux
node_js: "6"
env: NO_WATCH_TESTS=1 JOB_PART=test
env: NO_WATCH_TESTS=1 JOB_PART=integration
- os: linux
node_js: "4"
env: NO_WATCH_TESTS=1 JOB_PART=test
env: NO_WATCH_TESTS=1 JOB_PART=integration
- os: osx
node_js: "8"
env: NO_WATCH_TESTS=1 JOB_PART=test
env: NO_WATCH_TESTS=1 JOB_PART=integration
allow_failures:
- os: osx
fast_finish: true
Expand All @@ -38,7 +41,7 @@ script: npm run travis:$JOB_PART

after_success:
- cat ./coverage/lcov.info | node_modules/.bin/coveralls --verbose
- cat ./coverage/coverage.json | node_modules/codecov.io/bin/codecov.io.js
- bash <(curl -s https://codecov.io/bash) -F $JOB_PART
- rm -rf ./coverage

notifications:
Expand Down
9 changes: 5 additions & 4 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ branches:
init:
- git config --global core.autocrlf input

clone_depth: 50

# what combinations to test
environment:
matrix:
- nodejs_version: 8
job_part: test
job_part: unit
- nodejs_version: 8
job_part: integration
- nodejs_version: 6
job_part: test
job_part: integration

install:
- ps: Install-Product node $env:nodejs_version x64
Expand All @@ -36,3 +36,4 @@ test_script:
- npm --version
- yarn --version
- cmd: npm run appveyor:%job_part%
- cmd: npm install -g codecov && codecov -F %job_part%
29 changes: 23 additions & 6 deletions codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,29 @@ coverage:
range: "70...100"
status:
project:
default:
default: off
integration:
flags: integration
target: auto
unit:
flags: unit
target: 0%
patch:
default:
target: auto
default: off
integration:
flags: integration
target: 90%
base: pr
unit:
flags: unit
target: 0%
base: pr
changes:
default:
branches: null
comment: off
default: off
integration:
flags: integration
target: 0%
unit:
flags: unit
target: 0%
comment: off
6 changes: 3 additions & 3 deletions open-bot.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ rules:
pull_request:
mergeable: true
status:
context: "codecov/patch"
context: "codecov/patch/integration"
ensure:
value: "{{status.state}}"
equals: "success"
Expand All @@ -181,7 +181,7 @@ rules:
pull_request:
mergeable: true
status:
context: "codecov/patch"
context: "codecov/patch/integration"
ensure:
value: "{{status.state}}"
equals: "failure"
Expand All @@ -193,7 +193,7 @@ rules:
pull_request:
mergeable: true
status:
context: "codecov/patch"
context: "codecov/patch/integration"
ensure:
value: "{{status.state}}"
equals: "failure"
Expand Down
25 changes: 17 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
"benchmark": "^2.1.1",
"bundle-loader": "~0.5.0",
"codacy-coverage": "^2.0.1",
"codecov.io": "^0.1.2",
"coffee-loader": "~0.7.1",
"coffee-script": "^1.10.0",
"coveralls": "^2.11.2",
Expand All @@ -58,6 +57,7 @@
"raw-loader": "~0.5.0",
"react": "^15.2.1",
"react-dom": "^15.2.1",
"rimraf": "^2.6.2",
"script-loader": "~0.7.0",
"should": "^11.1.1",
"simple-git": "^1.65.0",
Expand Down Expand Up @@ -89,13 +89,17 @@
"schemas/"
],
"scripts": {
"test": "mocha test/*.test.js --max-old-space-size=4096 --harmony --check-leaks",
"travis:test": "npm run cover:min",
"test": "mocha test/*.test.js test/*.unittest.js --max-old-space-size=4096 --harmony --trace-deprecation --check-leaks",
"test:integration": "mocha test/*.test.js --max-old-space-size=4096 --harmony --trace-deprecation --check-leaks",
"test:unit": "mocha test/*.unittest.js --max-old-space-size=4096 --harmony --trace-deprecation --check-leaks",
"travis:integration": "npm run cover:init && npm run cover:integration && npm run cover:report-min",
"travis:unit": "npm run cover:init && npm run cover:unit && npm run cover:report-min",
"travis:lint": "npm run lint-files && npm run nsp",
"travis:benchmark": "npm run benchmark",
"appveyor:test": "node node_modules\\mocha\\bin\\mocha --max-old-space-size=4096 --harmony test/*.test.js",
"appveyor:integration": "npm run cover:init && npm run cover:integration && npm run cover:report-min",
"appveyor:unit": "npm run cover:init && npm run cover:unit && npm run cover:report-min",
"appveyor:benchmark": "npm run benchmark",
"circleci:test": "node node_modules/mocha/bin/mocha --max-old-space-size=4096 --harmony test/*.test.js",
"circleci:test": "node node_modules/mocha/bin/mocha --max-old-space-size=4096 --harmony --trace-deprecation test/*.test.js test/*.unittest.js",
"circleci:lint": "npm run lint-files && npm run nsp",
"build:examples": "cd examples && node buildAll.js",
"pretest": "npm run lint-files",
Expand All @@ -104,9 +108,14 @@
"fix": "npm run lint -- --fix",
"beautify-lint": "beautify-lint \"lib/**/*.js\" \"hot/**/*.js\" \"bin/**/*.js\" \"benchmark/*.js\" \"test/*.js\"",
"nsp": "nsp check --output summary",
"benchmark": "mocha --max-old-space-size=4096 --harmony test/*.benchmark.js -R spec",
"cover": "node --max-old-space-size=4096 --harmony ./node_modules/istanbul/lib/cli.js cover -x '**/*.runtime.js' node_modules/mocha/bin/_mocha -- test/*.test.js",
"cover:min": "node --max-old-space-size=4096 --harmony ./node_modules/istanbul/lib/cli.js cover -x '**/*.runtime.js' --report lcovonly node_modules/mocha/bin/_mocha -- test/*.test.js",
"benchmark": "mocha --max-old-space-size=4096 --harmony --trace-deprecation test/*.benchmark.js -R spec",
"cover": "npm run cover:init && npm run cover:all && npm run cover:report",
"cover:init": "rimraf coverage",
"cover:all": "node --max-old-space-size=4096 --harmony --trace-deprecation ./node_modules/istanbul/lib/cli.js cover --report none node_modules/mocha/bin/_mocha -- test/*.test.js test/*.unittest.js",
"cover:integration": "node --max-old-space-size=4096 --harmony --trace-deprecation ./node_modules/istanbul/lib/cli.js cover --report none node_modules/mocha/bin/_mocha -- test/*.test.js",
"cover:unit": "node --max-old-space-size=4096 --harmony --trace-deprecation ./node_modules/istanbul/lib/cli.js cover --report none node_modules/mocha/bin/_mocha -- test/*.unittest.js",
"cover:report": "istanbul report",
"cover:report-min": "istanbul report --report lcovonly",
"publish-patch": "npm run lint && npm run beautify-lint && mocha && npm version patch && git push && git push --tags && npm publish"
}
}
File renamed without changes.
16 changes: 13 additions & 3 deletions test/BinTestCases.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,17 @@
const should = require("should");
const path = require("path");
const fs = require("fs");
const spawn = require("child_process").spawn;
const child_process = require("child_process");

function spawn(args, options) {
if(process.env.running_under_istanbul) {
args = [require.resolve("istanbul/lib/cli.js"), "cover", "--report", "none", "--print", "none", "--include-pid", "--dir", path.resolve("coverage"), "--", require.resolve("./helpers/exec-in-directory.js"), options.cwd].concat(args);
options = Object.assign({}, options, {
cwd: undefined
});
}
return child_process.spawn(process.execPath, args, options);
}

function loadOptsFile(optsPath) {
// Options file parser from Mocha
Expand Down Expand Up @@ -73,7 +83,7 @@ describe("BinTestCases", function() {
describe(testName, function() {
it("should run successfully", function(done) {
this.timeout(10000);
const child = spawn(process.execPath, [cmd].concat(args), opts);
const child = spawn([cmd].concat(args), opts);

child.on("close", function(code) {
env.code = code;
Expand Down Expand Up @@ -108,7 +118,7 @@ describe("BinTestCases", function() {
before(function(done) {
this.timeout(20000);

const child = spawn(process.execPath, [cmd].concat(args), opts);
const child = spawn([cmd].concat(args), opts);

child.on("close", function(code) {
env.code = code;
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ describe("ModuleDependencyError", () => {

it("has a message property", () => env.moduleDependencyError.message.should.be.exactly("Location Error Message"));

it("has a details property", () => env.moduleDependencyError.details.should.containEql(path.join("test", "ModuleDependencyError.test.js:")));
it("has a details property", () => env.moduleDependencyError.details.should.containEql(path.join("test", "ModuleDependencyError.unittest.js:")));

it("has an origin property", () => env.moduleDependencyError.origin.should.be.exactly("myModule"));

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
89 changes: 89 additions & 0 deletions test/Stats.unittest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/*globals describe it */
"use strict";

require("should");

const Stats = require("../lib/Stats");

describe("Stats", () => {
describe("Error Handling", () => {
describe("does have", () => {
it("hasErrors", () => {
const mockStats = new Stats({
errors: ["firstError"],
hash: "1234"
});
mockStats.hasErrors().should.be.ok();
});
it("hasWarnings", () => {
const mockStats = new Stats({
warnings: ["firstError"],
hash: "1234"
});
mockStats.hasWarnings().should.be.ok();
});
});
describe("does not have", () => {
it("hasErrors", () => {
const mockStats = new Stats({
errors: [],
hash: "1234"
});
mockStats.hasErrors().should.not.be.ok();
});
it("hasWarnings", () => {
const mockStats = new Stats({
warnings: [],
hash: "1234"
});
mockStats.hasWarnings().should.not.be.ok();
});
});
it("formatError handles string errors", () => {
const mockStats = new Stats({
errors: ["firstError"],
warnings: [],
assets: [],
entrypoints: {},
chunks: [],
modules: [],
children: [],
hash: "1234",
mainTemplate: {
getPublicPath: () => "path"
}
});
const obj = mockStats.toJson();
obj.errors[0].should.be.equal("firstError");
});
});
describe("Presets", () => {
describe("presetToOptions", () => {
it("returns correct object with 'Normal'", () => {
Stats.presetToOptions("Normal").should.eql({});
});
it("truthy values behave as 'normal'", () => {
const normalOpts = Stats.presetToOptions("normal");
Stats.presetToOptions("pizza").should.eql(normalOpts);
Stats.presetToOptions(true).should.eql(normalOpts);
Stats.presetToOptions(1).should.eql(normalOpts);

Stats.presetToOptions("verbose").should.not.eql(normalOpts);
Stats.presetToOptions(false).should.not.eql(normalOpts);
});
it("returns correct object with 'none'", () => {
Stats.presetToOptions("none").should.eql({
all: false
});
});
it("falsy values behave as 'none'", () => {
const noneOpts = Stats.presetToOptions("none");
Stats.presetToOptions("").should.eql(noneOpts);
Stats.presetToOptions(null).should.eql(noneOpts);
Stats.presetToOptions().should.eql(noneOpts);
Stats.presetToOptions(0).should.eql(noneOpts);
Stats.presetToOptions(false).should.eql(noneOpts);
});
});
});
});
Loading

0 comments on commit 0c104a6

Please sign in to comment.