|
1 |
| -'use strict'; |
| 1 | +import assert from 'assert'; |
| 2 | +import fs from 'fs'; |
| 3 | +import path from 'path'; |
| 4 | +import FileSystemLoader from 'css-modules-loader-core/lib/file-system-loader'; |
2 | 5 |
|
3 |
| -import assert from 'assert' |
4 |
| -import fs from 'fs' |
5 |
| -import path from 'path' |
6 |
| -import FileSystemLoader from 'css-modules-loader-core/lib/file-system-loader' |
7 |
| - |
8 |
| -let normalize = ( str ) => { |
9 |
| - return str.replace( /\r\n?/g, '\n' ); |
10 |
| -} |
| 6 | +const normalize = str => { |
| 7 | + return str.replace(/\r\n?/g, '\n'); |
| 8 | +}; |
11 | 9 |
|
12 | 10 | const pipelines = {
|
13 | 11 | 'test-cases': undefined,
|
14 |
| - 'cssi': [] |
15 |
| -} |
| 12 | + 'cssi': [], |
| 13 | +}; |
16 | 14 |
|
17 |
| -describe('css-modules-loader-core', function () { |
| 15 | +describe('css-modules-loader-core', () => { |
18 | 16 | Object.keys( pipelines ).forEach( dirname => {
|
19 | 17 | describe( dirname, () => {
|
20 |
| - let testDir = path.join( __dirname, dirname ) |
| 18 | + const testDir = path.join(__dirname, dirname); |
21 | 19 |
|
22 |
| - fs.readdirSync( testDir ).forEach( testCase => { |
23 |
| - if ( fs.existsSync( path.join( testDir, testCase, 'source.css' ) ) ) { |
| 20 | + fs.readdirSync(testDir).forEach(testCase => { |
| 21 | + if (fs.existsSync(path.join(testDir, testCase, 'source.css'))) { |
24 | 22 | it( 'should ' + testCase.replace( /-/g, ' ' ), done => {
|
25 |
| - let expected = normalize( fs.readFileSync( path.join( testDir, testCase, 'expected.css' ), 'utf-8' ) ) |
26 |
| - let loader = new FileSystemLoader( testDir, pipelines[dirname] ) |
27 |
| - let expectedTokens = JSON.parse( fs.readFileSync( path.join( testDir, testCase, 'expected.json' ), 'utf-8' ) ) |
28 |
| - |
29 |
| - loader.fetch( `${testCase}/source.css`, '/' ).then( tokens => { |
30 |
| - assert.equal( loader.finalSource, expected ) |
31 |
| - assert.equal( JSON.stringify( tokens ), JSON.stringify( expectedTokens ) ) |
32 |
| - } ).then( done, done ) |
33 |
| - } ); |
| 23 | + const expected = normalize(fs.readFileSync(path.join(testDir, testCase, 'expected.css'), 'utf-8')); |
| 24 | + const loader = new FileSystemLoader(testDir, pipelines[dirname]); |
| 25 | + const expectedTokens = JSON.parse(fs.readFileSync(path.join(testDir, testCase, 'expected.json'), 'utf-8')); |
| 26 | + |
| 27 | + loader.fetch(`${testCase}/source.css`, '/').then(tokens => { |
| 28 | + assert.equal(loader.finalSource, expected); |
| 29 | + assert.equal(JSON.stringify( tokens ), JSON.stringify(expectedTokens)); |
| 30 | + }).then(done, done); |
| 31 | + }); |
34 | 32 | }
|
35 |
| - } ); |
36 |
| - } ); |
37 |
| - } ) |
| 33 | + }); |
| 34 | + }); |
| 35 | + }); |
38 | 36 |
|
39 | 37 | // special case for testing multiple sources
|
40 | 38 | describe( 'multiple sources', () => {
|
41 |
| - let testDir = path.join( __dirname, 'test-cases' ) |
42 |
| - let testCase = 'multiple-sources'; |
43 |
| - let dirname = 'test-cases'; |
| 39 | + const testDir = path.join(__dirname, 'test-cases'); |
| 40 | + const testCase = 'multiple-sources'; |
| 41 | + const dirname = 'test-cases'; |
44 | 42 |
|
45 | 43 | if ( fs.existsSync( path.join( testDir, testCase, 'source1.css' ) ) ) {
|
46 | 44 | it( 'should ' + testCase.replace( /-/g, ' ' ), done => {
|
47 |
| - let expected = normalize( fs.readFileSync( path.join( testDir, testCase, 'expected.css' ), 'utf-8' ) ) |
48 |
| - let loader = new FileSystemLoader( testDir, pipelines[dirname] ) |
49 |
| - let expectedTokens = JSON.parse( fs.readFileSync( path.join( testDir, testCase, 'expected.json' ), 'utf-8' ) ) |
| 45 | + const expected = normalize(fs.readFileSync(path.join(testDir, testCase, 'expected.css'), 'utf-8')); |
| 46 | + const loader = new FileSystemLoader(testDir, pipelines[dirname]); |
| 47 | + const expectedTokens = JSON.parse(fs.readFileSync(path.join(testDir, testCase, 'expected.json'), 'utf-8')); |
50 | 48 |
|
51 |
| - loader.fetch( `${testCase}/source1.css`, '/' ).then( tokens1 => { |
52 |
| - loader.fetch( `${testCase}/source2.css`, '/' ).then( tokens2 => { |
53 |
| - assert.equal( loader.finalSource, expected ) |
| 49 | + loader.fetch(`${testCase}/source1.css`, '/').then(tokens1 => { |
| 50 | + loader.fetch(`${testCase}/source2.css`, '/').then(tokens2 => { |
| 51 | + assert.equal(loader.finalSource, expected); |
54 | 52 | const tokens = Object.assign({}, tokens1, tokens2);
|
55 |
| - assert.equal( JSON.stringify( tokens ), JSON.stringify( expectedTokens ) ) |
56 |
| - } ).then( done, done ) |
57 |
| - }) |
58 |
| - } ); |
| 53 | + assert.equal(JSON.stringify(tokens), JSON.stringify(expectedTokens)); |
| 54 | + }).then(done, done); |
| 55 | + }); |
| 56 | + }); |
59 | 57 | }
|
60 |
| - } ); |
| 58 | + }); |
61 | 59 | });
|
0 commit comments