|
| 1 | +import { execSync } from 'child_process'; |
| 2 | +import glob from 'glob'; |
| 3 | +import path from 'path'; |
| 4 | +import fs from 'fs-extra'; |
| 5 | + |
| 6 | +const bin = './dist/cli.js'; |
| 7 | +const cache = path.join(__dirname, '.cache'); |
| 8 | + |
| 9 | +const run = (recipe: string) => { |
| 10 | + // Setup the test files |
| 11 | + const originalInput = `./recipes/${recipe}/input`; |
| 12 | + const inputDest = path.resolve(cache, recipe); |
| 13 | + fs.copySync(originalInput, inputDest); |
| 14 | + |
| 15 | + // Run the command |
| 16 | + const transform = `./recipes/${recipe}/transform.ts`; |
| 17 | + const inputGlob = `${inputDest}/**/*.css`; |
| 18 | + const command = `${bin} -t ${transform} '${inputGlob}'`; |
| 19 | + execSync(command); |
| 20 | + |
| 21 | + // Compare results |
| 22 | + const expectedOutput = `./recipes/${recipe}/output`; |
| 23 | + const expectedOutputGlob = `${expectedOutput}/**/*.css`; |
| 24 | + const expectedFiles = glob.sync(expectedOutputGlob); |
| 25 | + |
| 26 | + expectedFiles.forEach(expectedFile => { |
| 27 | + const uniquePath = path.relative(expectedOutput, expectedFile); |
| 28 | + const actualFilePath = path.join(inputDest, uniquePath); |
| 29 | + const expectedContent = fs.readFileSync(expectedFile).toString(); |
| 30 | + const actualContent = fs.readFileSync(actualFilePath).toString(); |
| 31 | + expect(actualContent).toEqual(expectedContent); |
| 32 | + }); |
| 33 | +}; |
| 34 | + |
| 35 | +const recipes = fs.readdirSync(path.resolve(__dirname, '../recipes')); |
| 36 | + |
1 | 37 | describe('cli', () => {
|
2 |
| - it('should perform file transformations', () => { |
3 |
| - // cli(); |
| 38 | + beforeAll(() => { |
| 39 | + fs.removeSync(cache); |
| 40 | + }); |
| 41 | + |
| 42 | + afterAll(() => { |
| 43 | + fs.removeSync(cache); |
| 44 | + }); |
| 45 | + |
| 46 | + it.each(recipes)('should perform %s transform correctly', recipe => { |
| 47 | + run(recipe); |
4 | 48 | });
|
5 | 49 | });
|
0 commit comments