Skip to content

Commit 5253a32

Browse files
authored
Merge pull request #52 from Turbo87/simplify-tests
Simplify test code
2 parents 8819f71 + 1566970 commit 5253a32

File tree

3 files changed

+16
-32
lines changed

3 files changed

+16
-32
lines changed

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
"babel-preset-latest": "^6.24.0",
66
"babel-register": "^6.22.0",
77
"chai": "^3.5.0",
8-
"chai-files": "^1.4.0",
98
"mocha": "^3.2.0"
109
},
1110
"name": "babel-plugin-debug-macros",

src/tests/debug-tools-test.js

Lines changed: 16 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
const DebugToolsPlugin = require('../index');
44
const transform = require('babel-core').transform;
55
const expect = require('chai').expect;
6-
const file = require('chai-files').file;
7-
const lstatSync = require('fs').lstatSync;
6+
const fs = require('fs');
87

98
const presets = [["latest", {
109
"es2015": false,
@@ -435,50 +434,42 @@ let cases = {
435434
},
436435
}
437436

438-
function compile(source, transformOptions) {
439-
return transform(source, transformOptions);
440-
}
441-
442437
Object.keys(cases).forEach(caseName => {
443438
describe(caseName, () => {
444439
let ep = 0;
445440

446-
cases[caseName].fixtures.forEach(assertionName => {
447-
if (cases[caseName].only) {
441+
let testcase = cases[caseName];
442+
443+
testcase.fixtures.forEach(assertionName => {
444+
if (testcase.only) {
448445
it.only(assertionName, () => {
449-
test(caseName, cases, assertionName, ep);
446+
test(testcase, assertionName, ep);
450447
});
451-
} else if (cases[caseName].skip) {
448+
} else if (testcase.skip) {
452449
it.skip(assertionName, () => {});
453450
} else {
454451
it(assertionName, () => {
455-
test(caseName, cases, assertionName, ep);
452+
test(testcase, assertionName, ep);
456453
});
457454
}
458455
});
459456
});
460457
});
461458

462459

463-
function test(caseName, cases, assertionName, ep) {
464-
let sample = file(`./fixtures/${assertionName}/sample.js`).content;
465-
let options = cases[caseName].transformOptions;
460+
function test(testcase, assertionName, ep) {
461+
let sample = fs.readFileSync(`./fixtures/${assertionName}/sample.js`, 'utf-8');
462+
let options = testcase.transformOptions;
466463
let expectationPath = `./fixtures/${assertionName}/expectation.js`;
467-
let expectationExists = true;
468-
469-
try {
470-
lstatSync(expectationPath);
471-
} catch (e) {
472-
expectationExists = false
473-
}
464+
let expectationExists = fs.existsSync(expectationPath);
474465

475466
if (expectationExists) {
476-
let expectation = file(`./fixtures/${assertionName}/expectation.js`).content;
477-
let compiled = compile(sample, options);
467+
let expectation = fs.readFileSync(expectationPath, 'utf-8');
468+
let compiled = transform(sample, options);
478469
expect(compiled.code).to.equal(expectation);
479470

480471
} else {
481-
let fn = () => compile(sample, options);
482-
expect(fn).to.throw(new RegExp(cases[caseName].errors[ep++]));
472+
let fn = () => transform(sample, options);
473+
expect(fn).to.throw(new RegExp(testcase.errors[ep++]));
483474
}
484475
}

yarn.lock

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -594,12 +594,6 @@ caniuse-db@^1.0.30000639:
594594
version "1.0.30000640"
595595
resolved "https://registry.yarnpkg.com/caniuse-db/-/caniuse-db-1.0.30000640.tgz#7b7fd3cf13c0d9d41f8754b577b202113e2be7ca"
596596

597-
chai-files@^1.4.0:
598-
version "1.4.0"
599-
resolved "https://registry.yarnpkg.com/chai-files/-/chai-files-1.4.0.tgz#0e25610fadc551b1eae79c2f4ee79faf2f842296"
600-
dependencies:
601-
assertion-error "^1.0.1"
602-
603597
chai@^3.5.0:
604598
version "3.5.0"
605599
resolved "https://registry.yarnpkg.com/chai/-/chai-3.5.0.tgz#4d02637b067fe958bdbfdd3a40ec56fef7373247"

0 commit comments

Comments
 (0)