|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +import '../src'; |
| 4 | +import fs from 'fs' |
| 5 | +import path from 'path' |
| 6 | +import { equal } from 'assert'; |
| 7 | + |
| 8 | +const pipelines = { |
| 9 | + 'test-cases': undefined, |
| 10 | + 'cssi': [] |
| 11 | +} |
| 12 | + |
| 13 | +Object.keys(pipelines).forEach(dirname => { |
| 14 | + describe(dirname, () => { |
| 15 | + let testDir = path.join(__dirname, dirname); |
| 16 | + |
| 17 | + fs.readdirSync(testDir).forEach(testCase => { |
| 18 | + if (fs.existsSync(path.join(testDir, testCase, 'source.css'))) { |
| 19 | + it('should ' + testCase.replace(/-/g, ' '), done => { |
| 20 | + let expectedTokens = JSON.parse(fs.readFileSync(path.join(testDir, testCase, 'expected.json'), 'utf-8')); |
| 21 | + let tokens = require(`${testDir}/${testCase}/source.css`); |
| 22 | + |
| 23 | + equal(JSON.stringify(tokens), JSON.stringify(expectedTokens)); |
| 24 | + }); |
| 25 | + } |
| 26 | + }); |
| 27 | + }); |
| 28 | +}); |
| 29 | + |
| 30 | +// special case for testing multiple sources |
| 31 | +describe( 'multiple sources', () => { |
| 32 | + let testDir = path.join(__dirname, 'test-cases'); |
| 33 | + let testCase = 'multiple-sources'; |
| 34 | + let dirname = 'test-cases'; |
| 35 | + |
| 36 | + if (fs.existsSync(path.join(testDir, testCase, 'source1.css'))) { |
| 37 | + it('should ' + testCase.replace(/-/g, ' '), done => { |
| 38 | + let expectedTokens = JSON.parse(fs.readFileSync(path.join(testDir, testCase, 'expected.json'), 'utf-8')); |
| 39 | + let tokens1 = require(`${testDir}/${testCase}/source1.css`); |
| 40 | + let tokens2 = require(`${testDir}/${testCase}/source2.css`); |
| 41 | + let tokens = Object.assign({}, tokens1, tokens2); |
| 42 | + |
| 43 | + equal(JSON.stringify(tokens), JSON.stringify(expectedTokens)); |
| 44 | + }); |
| 45 | + } |
| 46 | +}); |
0 commit comments