Skip to content

Commit

Permalink
Merge pull request #898 from secretcowlevel/master
Browse files Browse the repository at this point in the history
Switch back to Hoek.clone from lodash.deepClone.
  • Loading branch information
geek authored Dec 17, 2018
2 parents 47e8181 + a9c6b7a commit 5c11479
Show file tree
Hide file tree
Showing 9 changed files with 64 additions and 22 deletions.
4 changes: 4 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
* text=auto eol=lf
*.new text eol=lf
*.inl text eol=lf
*.js text eol=lf
5 changes: 5 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,9 @@ node_js:
- "11"
- "node"

os:
- linux
- osx
- windows

sudo: false
2 changes: 1 addition & 1 deletion lib/reporters/console.js
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ internals.color = function (name, code, enabled) {
internals.colors = function (enabled) {

if (enabled === null) {
enabled = require('supports-color');
enabled = require('supports-color').stdout;
}

const codes = {
Expand Down
4 changes: 2 additions & 2 deletions lib/reporters/multiple.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

// Load modules

const { cloneDeep } = require('lodash');
const Hoek = require('hoek');
const Reporters = require('./index');


Expand All @@ -17,7 +17,7 @@ exports = module.exports = internals.Reporter = function (options) {

options.reporter.forEach((reporter, index) => {

const reporterOptions = cloneDeep(options);
const reporterOptions = Hoek.clone(options);
reporterOptions.reporter = reporter;

if (options.output[index] === 'stdout') {
Expand Down
5 changes: 2 additions & 3 deletions lib/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// Load modules

const Hoek = require('hoek');
const { cloneDeep } = require('lodash');
const Seedrandom = require('seedrandom');
const WillCall = require('will-call');
const Reporters = require('./reporters');
Expand Down Expand Up @@ -264,7 +263,7 @@ internals.executeExperiments = async function (experiments, state, skip, parentC
for (const experiment of experiments) {
const skipExperiment = skip || experiment.options.skip || !internals.experimentHasTests(experiment, state) || (state.options.bail && state.report.failures);

state.currentContext = parentContext ? cloneDeep(parentContext) : {};
state.currentContext = parentContext ? Hoek.clone(parentContext) : {};

// Before

Expand Down Expand Up @@ -372,7 +371,7 @@ internals.executeTests = async function (experiment, state, skip) {

const start = Date.now();
try {
test.context = cloneDeep(state.currentContext);
test.context = Hoek.clone(state.currentContext);
await internals.protect(test, state);
}
catch (ex) {
Expand Down
18 changes: 9 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,39 +10,39 @@
"dependencies": {
"bossy": "4.x.x",
"diff": "3.5.x",
"eslint": "5.9.x",
"eslint": "5.10.x",
"eslint-config-hapi": "12.x.x",
"eslint-plugin-hapi": "4.x.x",
"espree": "4.1.x",
"espree": "5.0.x",
"find-rc": "3.0.x",
"handlebars": "4.x.x",
"hoek": "6.x.x",
"hoek": "6.1.x",
"json-stable-stringify": "1.x.x",
"json-stringify-safe": "5.x.x",
"lodash": "^4.17.x",
"mkdirp": "0.5.x",
"seedrandom": "2.4.x",
"source-map": "0.7.x",
"source-map-support": "0.5.x",
"supports-color": "4.4.x",
"supports-color": "5.5.x",
"will-call": "1.x.x"
},
"devDependencies": {
"code": "5.x.x",
"cpr": "3.0.x",
"eslint-plugin-markdown": "1.0.0-rc.0",
"lab-event-reporter": "1.x.x",
"rimraf": "2.6.x"
"rimraf": "2.6.x",
"semver": "5.6.x"
},
"bin": {
"lab": "./bin/lab"
},
"scripts": {
"test": "node ./bin/_lab -fL -t 100 -m 3000",
"test": "node ./bin/_lab -fL -t 100 -m 10000",
"posttest": "npm run lint-md",
"test-cov-html": "node ./bin/_lab -fL -r html -m 3000 -o coverage.html",
"test-cov-html": "node ./bin/_lab -fL -r html -m 10000 -o coverage.html",
"lint": "node ./bin/_lab -d -f -L",
"lint-md": "eslint --config hapi --rule 'strict: 0, eol-last: 0' --plugin markdown --ext md --parser-options 'ecmaVersion: 9' ."
"lint-md": "eslint --config hapi --rule \"strict: 0, eol-last: 0\" --plugin markdown --ext md --parser-options \"ecmaVersion: 9\" ."
},
"license": "BSD-3-Clause"
}
3 changes: 2 additions & 1 deletion test/leaks.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// Load modules

const Code = require('code');
const Semver = require('semver');
const _Lab = require('../test_runner');
const Lab = require('../');

Expand Down Expand Up @@ -100,7 +101,7 @@ describe('Leaks', () => {
expect(leaks.length).to.equal(0);
});

it('ignores Counter globals', () => {
it('ignores Counter globals', { skip: process.platform === 'win32' && Semver.gte(process.version, '11.0.0') }, () => {

const counterGlobals = internals.counterGlobals;
testedKeys = internals.counterGlobals;
Expand Down
2 changes: 1 addition & 1 deletion test/linters.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ describe('Linters - eslint', () => {
Fs.writeFileSync = (path, output) => {

expect(path).to.endWith(Path.join('test', 'lint', 'eslint', 'fix', 'success.js'));
expect(output).to.endWith('\n return value;\n};\n');
expect(output).to.match(/\r?\n return value;\r?\n\};\r?\n/);
isFixed = true;
};

Expand Down
43 changes: 38 additions & 5 deletions test/reporters.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const Crypto = require('crypto');
const Fs = require('fs');
const Os = require('os');
const Path = require('path');
const Rimraf = require('rimraf');
const Stream = require('stream');
const Code = require('code');
const _Lab = require('../test_runner');
Expand Down Expand Up @@ -101,8 +102,7 @@ describe('Reporter', () => {

expect(code).to.equal(0);
expect(output).to.equal(Fs.readFileSync(filename).toString());
Fs.unlinkSync(filename);
Fs.rmdirSync(folder);
Rimraf.sync(folder);
});

it('outputs to a file with output is passed as an array and reporter is an array', async () => {
Expand Down Expand Up @@ -683,7 +683,7 @@ describe('Reporter', () => {
});

const { output } = await Lab.report(script, { reporter: 'console', progress: 0, output: false, assert: false });
expect(output).to.match(/^\u001b\[32m1 tests complete\u001b\[0m\nTest duration: \d+ ms\n\u001b\[32mNo global variable leaks detected\u001b\[0m\n\n$/);
expect(output).to.match(/^(\u001b\[32m)?1 tests complete(\u001b\[0m)?\nTest duration: \d+ ms\n(\u001b\[32m)?No global variable leaks detected(\u001b\[0m)?\n\n$/);
});

it('generates a report with verbose progress', async () => {
Expand All @@ -695,7 +695,7 @@ describe('Reporter', () => {
});

const { output } = await Lab.report(script, { reporter: 'console', progress: 2, output: false, assert: false });
expect(output).to.match(/^test\n \u001b\[32m[✔√]\u001b\[0m \u001b\[90m1\) works \(\d+ ms\)\u001b\[0m\n\n\n\u001b\[32m1 tests complete\u001b\[0m\nTest duration: \d+ ms\n\u001b\[32mNo global variable leaks detected\u001b\[0m\n\n$/);
expect(output).to.match(/^test\n (\u001b\[32m)?[✔√](\u001b\[0m)? (\u001b\[90m)?1\) works \(\d+ ms\)(\u001b\[0m)?\n\n\n(\u001b\[32m)?1 tests complete(\u001b\[0m)?\nTest duration: \d+ ms\n(\u001b\[32m)?No global variable leaks detected(\u001b\[0m)?\n\n$/);
});

it('generates a report with verbose progress with experiments with same named tests', async () => {
Expand Down Expand Up @@ -763,7 +763,7 @@ describe('Reporter', () => {
});

const { output } = await Lab.report(script, { reporter: 'console', progress: 2, assert: Code, output: false });
expect(output).to.match(/^test\n \u001b\[32m[✔√]\u001b\[0m \u001b\[90m1\) works \(\d+ ms and \d+ assertions\)\u001b\[0m\n\n\n\u001b\[32m1 tests complete\u001b\[0m\nTest duration: \d+ ms\nAssertions count\: \d+ \(verbosity\: \d+\.\d+\)\n\u001b\[32mNo global variable leaks detected\u001b\[0m\n\n$/);
expect(output).to.match(/^test\n (\u001b\[32m)?[✔√](\u001b\[0m)? (\u001b\[90m)?1\) works \(\d+ ms and \d+ assertions\)(\u001b\[0m)?\n\n\n(\u001b\[32m)?1 tests complete(\u001b\[0m)?\nTest duration: \d+ ms\nAssertions count\: \d+ \(verbosity\: \d+\.\d+\)\n(\u001b\[32m)?No global variable leaks detected(\u001b\[0m)?\n\n$/);
});

it('generates a report with verbose progress that displays well on windows', async () => {
Expand Down Expand Up @@ -999,6 +999,39 @@ describe('Reporter', () => {
expect(output).to.match(/^\n \n \.\n\n1 tests complete\nTest duration: \d+ ms\nNo global variable leaks detected\n\n$/);
});

it('includes colors when terminal supports', async () => {

delete require.cache[require.resolve('supports-color')];
const orig = {
isTTY: process.stdout.isTTY,
env: process.env
};
process.stdout.isTTY = true;
process.env = {
FORCE_COLOR: true
};

const script = Lab.script();
script.experiment('test', () => {

script.test('works', () => {

expect(true).to.equal(true);
});
script.test('does not work', () => {

expect(true).to.equal(false);
});
});

const { code, output } = await Lab.report(script, { reporter: 'console', output: false, assert: false });

process.stdout.isTTY = orig.isTTY;
process.env = orig.env;
expect(code).to.equal(1);
expect(output).to.match(/^\n \n \.\u001b\[31mx\u001b\[0m\n\nFailed tests:\n\n 2\) test does not work:\n\n \u001b\[37;41mactual\u001b\[0m \u001b\[30;42mexpected\u001b\[0m\n\n \u001b\[37;41mtrue\u001b\[0m\u001b\[30;42mfalse\u001b\[0m\n\n \u001b\[33mExpected true to equal specified value: false\u001b\[0m\n\n.*?\u001b\[0m\n\n\n\u001b\[31m1 of 2 tests failed\u001b\[0m\nTest duration: \d+ ms\n\u001b\[32mNo global variable leaks detected\u001b\[0m\n\n$/);
});

it('displays custom error messages in expect', async () => {

const script = Lab.script();
Expand Down

0 comments on commit 5c11479

Please sign in to comment.