|
| 1 | +/* eslint-env: node */ |
1 | 2 | 'use strict'; |
2 | 3 |
|
3 | | -const defineTest = require('jscodeshift/dist/testUtils').defineTest; |
| 4 | +const fs = require('fs'); |
| 5 | +const path = require('path'); |
4 | 6 |
|
5 | | -defineTest(__dirname, 'import-it-from-mocha', {}, 'import-it-from-mocha/basic'); |
6 | | -defineTest(__dirname, 'import-it-from-mocha', {}, 'import-it-from-mocha/test-helper'); |
7 | | -defineTest(__dirname, 'import-it-from-mocha', {}, 'import-it-from-mocha/with-comment'); |
8 | | -defineTest(__dirname, 'import-it-from-mocha', {}, 'import-it-from-mocha/with-comment2'); |
9 | | -defineTest(__dirname, 'import-it-from-mocha', {}, 'import-it-from-mocha/with-comment3'); |
10 | | -defineTest(__dirname, 'import-it-from-mocha', {}, 'import-it-from-mocha/with-other-imports'); |
| 7 | +const runInlineTest = require('jscodeshift/dist/testUtils').runInlineTest; |
| 8 | +const ImportItFromMochaTransform = require('../import-it-from-mocha'); |
| 9 | +const fixtureFolder = `${__dirname}/../__testfixtures__/import-it-from-mocha`; |
| 10 | + |
| 11 | +describe('import-it-from-mocha', function() { |
| 12 | + fs |
| 13 | + .readdirSync(fixtureFolder) |
| 14 | + .filter(filename => /\.input\.js$/.test(filename)) |
| 15 | + .forEach(filename => { |
| 16 | + let testName = filename.replace('.input.js', ''); |
| 17 | + let inputPath = path.join(fixtureFolder, `${testName}.input.js`); |
| 18 | + let outputPath = path.join(fixtureFolder, `${testName}.output.js`); |
| 19 | + |
| 20 | + describe(testName, function() { |
| 21 | + it('transforms correctly', function() { |
| 22 | + runInlineTest( |
| 23 | + ImportItFromMochaTransform, |
| 24 | + {}, |
| 25 | + { source: fs.readFileSync(inputPath, 'utf8') }, |
| 26 | + fs.readFileSync(outputPath, 'utf8') |
| 27 | + ); |
| 28 | + }); |
| 29 | + |
| 30 | + it('is idempotent', function() { |
| 31 | + runInlineTest( |
| 32 | + ImportItFromMochaTransform, |
| 33 | + {}, |
| 34 | + { source: fs.readFileSync(outputPath, 'utf8') }, |
| 35 | + fs.readFileSync(outputPath, 'utf8') |
| 36 | + ); |
| 37 | + }); |
| 38 | + }); |
| 39 | + }); |
| 40 | +}); |
0 commit comments