|
3 | 3 | const DebugToolsPlugin = require('../index');
|
4 | 4 | const transform = require('babel-core').transform;
|
5 | 5 | const expect = require('chai').expect;
|
6 |
| -const file = require('chai-files').file; |
7 |
| -const lstatSync = require('fs').lstatSync; |
| 6 | +const fs = require('fs'); |
8 | 7 |
|
9 | 8 | const presets = [["latest", {
|
10 | 9 | "es2015": false,
|
@@ -435,50 +434,42 @@ let cases = {
|
435 | 434 | },
|
436 | 435 | }
|
437 | 436 |
|
438 |
| -function compile(source, transformOptions) { |
439 |
| - return transform(source, transformOptions); |
440 |
| -} |
441 |
| - |
442 | 437 | Object.keys(cases).forEach(caseName => {
|
443 | 438 | describe(caseName, () => {
|
444 | 439 | let ep = 0;
|
445 | 440 |
|
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) { |
448 | 445 | it.only(assertionName, () => {
|
449 |
| - test(caseName, cases, assertionName, ep); |
| 446 | + test(testcase, assertionName, ep); |
450 | 447 | });
|
451 |
| - } else if (cases[caseName].skip) { |
| 448 | + } else if (testcase.skip) { |
452 | 449 | it.skip(assertionName, () => {});
|
453 | 450 | } else {
|
454 | 451 | it(assertionName, () => {
|
455 |
| - test(caseName, cases, assertionName, ep); |
| 452 | + test(testcase, assertionName, ep); |
456 | 453 | });
|
457 | 454 | }
|
458 | 455 | });
|
459 | 456 | });
|
460 | 457 | });
|
461 | 458 |
|
462 | 459 |
|
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; |
466 | 463 | 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); |
474 | 465 |
|
475 | 466 | 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); |
478 | 469 | expect(compiled.code).to.equal(expectation);
|
479 | 470 |
|
480 | 471 | } 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++])); |
483 | 474 | }
|
484 | 475 | }
|
0 commit comments