Skip to content

Commit e48ea4f

Browse files
committed
scoped tests with names
1 parent 35076a2 commit e48ea4f

File tree

2 files changed

+84
-72
lines changed

2 files changed

+84
-72
lines changed

test/test-cases.js

Lines changed: 41 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -14,46 +14,48 @@ const pipelines = {
1414
'cssi': []
1515
}
1616

17-
Object.keys( pipelines ).forEach( dirname => {
18-
describe( dirname, () => {
19-
let testDir = path.join( __dirname, dirname )
20-
21-
fs.readdirSync( testDir ).forEach( testCase => {
22-
if ( fs.existsSync( path.join( testDir, testCase, 'source.css' ) ) ) {
23-
it( 'should ' + testCase.replace( /-/g, ' ' ), done => {
24-
let expected = normalize( fs.readFileSync( path.join( testDir, testCase, 'expected.css' ), 'utf-8' ) )
25-
let loader = new FileSystemLoader( testDir, pipelines[dirname] )
26-
let expectedTokens = JSON.parse( fs.readFileSync( path.join( testDir, testCase, 'expected.json' ), 'utf-8' ) )
27-
28-
loader.fetch( `${testCase}/source.css`, '/' ).then( tokens => {
17+
describe('css-modules-loader-core', function () {
18+
Object.keys( pipelines ).forEach( dirname => {
19+
describe( dirname, () => {
20+
let testDir = path.join( __dirname, dirname )
21+
22+
fs.readdirSync( testDir ).forEach( testCase => {
23+
if ( fs.existsSync( path.join( testDir, testCase, 'source.css' ) ) ) {
24+
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+
} );
34+
}
35+
} );
36+
} );
37+
} )
38+
39+
// special case for testing multiple sources
40+
describe( 'multiple sources', () => {
41+
let testDir = path.join( __dirname, 'test-cases' )
42+
let testCase = 'multiple-sources';
43+
let dirname = 'test-cases';
44+
45+
if ( fs.existsSync( path.join( testDir, testCase, 'source1.css' ) ) ) {
46+
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' ) )
50+
51+
loader.fetch( `${testCase}/source1.css`, '/' ).then( tokens1 => {
52+
loader.fetch( `${testCase}/source2.css`, '/' ).then( tokens2 => {
2953
assert.equal( loader.finalSource, expected )
54+
const tokens = Object.assign({}, tokens1, tokens2);
3055
assert.equal( JSON.stringify( tokens ), JSON.stringify( expectedTokens ) )
3156
} ).then( done, done )
32-
} );
33-
}
34-
} );
57+
})
58+
} );
59+
}
3560
} );
36-
} )
37-
38-
// special case for testing multiple sources
39-
describe( 'multiple sources', () => {
40-
let testDir = path.join( __dirname, 'test-cases' )
41-
let testCase = 'multiple-sources';
42-
let dirname = 'test-cases';
43-
44-
if ( fs.existsSync( path.join( testDir, testCase, 'source1.css' ) ) ) {
45-
it( 'should ' + testCase.replace( /-/g, ' ' ), done => {
46-
let expected = normalize( fs.readFileSync( path.join( testDir, testCase, 'expected.css' ), 'utf-8' ) )
47-
let loader = new FileSystemLoader( testDir, pipelines[dirname] )
48-
let expectedTokens = JSON.parse( fs.readFileSync( path.join( testDir, testCase, 'expected.json' ), 'utf-8' ) )
49-
50-
loader.fetch( `${testCase}/source1.css`, '/' ).then( tokens1 => {
51-
loader.fetch( `${testCase}/source2.css`, '/' ).then( tokens2 => {
52-
assert.equal( loader.finalSource, expected )
53-
const tokens = Object.assign({}, tokens1, tokens2);
54-
assert.equal( JSON.stringify( tokens ), JSON.stringify( expectedTokens ) )
55-
} ).then( done, done )
56-
})
57-
} );
58-
}
59-
} );
61+
});

test/test-hook.js

Lines changed: 43 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -4,46 +4,56 @@ import fs from 'fs'
44
import path from 'path'
55
import { equal } from 'assert';
66

7-
import hook from '../src';
7+
import hook from '../';
88

99
const pipelines = {
1010
'test-cases': undefined,
1111
'cssi': []
1212
}
1313

14-
Object.keys(pipelines).forEach(dirname => {
15-
describe(dirname, () => {
16-
let testDir = path.join(__dirname, dirname);
17-
18-
fs.readdirSync(testDir).forEach(testCase => {
19-
if (fs.existsSync(path.join(testDir, testCase, 'source.css'))) {
20-
it('should ' + testCase.replace(/-/g, ' '), () => {
21-
hook({use: pipelines[dirname]});
22-
let expectedTokens = JSON.parse(fs.readFileSync(path.join(testDir, testCase, 'expected.json'), 'utf-8'));
23-
let tokens = require(`${testDir}/${testCase}/source.css`);
24-
25-
equal(JSON.stringify(tokens), JSON.stringify(expectedTokens));
26-
});
27-
}
14+
describe('css-modules-require-hook', function () {
15+
Object.keys(pipelines).forEach(dirname => {
16+
describe(dirname, () => {
17+
let testDir = path.join(__dirname, dirname);
18+
19+
fs.readdirSync(testDir).forEach(testCase => {
20+
if (fs.existsSync(path.join(testDir, testCase, 'source.css'))) {
21+
it('should ' + testCase.replace(/-/g, ' '), () => {
22+
hook({
23+
root: testDir,
24+
use: pipelines[dirname]
25+
});
26+
27+
let expectedTokens = JSON.parse(fs.readFileSync(path.join(testDir, testCase, 'expected.json'), 'utf-8'));
28+
let tokens = require(`${testDir}/${testCase}/source.css`);
29+
30+
equal(JSON.stringify(tokens), JSON.stringify(expectedTokens));
31+
});
32+
}
33+
});
2834
});
2935
});
30-
});
3136

32-
// special case for testing multiple sources
33-
describe( 'multiple sources', () => {
34-
let testDir = path.join(__dirname, 'test-cases');
35-
let testCase = 'multiple-sources';
36-
let dirname = 'test-cases';
37-
38-
if (fs.existsSync(path.join(testDir, testCase, 'source1.css'))) {
39-
it('should ' + testCase.replace(/-/g, ' '), () => {
40-
hook({use: pipelines[dirname]});
41-
let expectedTokens = JSON.parse(fs.readFileSync(path.join(testDir, testCase, 'expected.json'), 'utf-8'));
42-
let tokens1 = require(`${testDir}/${testCase}/source1.css`);
43-
let tokens2 = require(`${testDir}/${testCase}/source2.css`);
44-
let tokens = Object.assign({}, tokens1, tokens2);
45-
46-
equal(JSON.stringify(tokens), JSON.stringify(expectedTokens));
47-
});
48-
}
37+
// special case for testing multiple sources
38+
describe('multiple sources', () => {
39+
let testDir = path.join(__dirname, 'test-cases');
40+
let testCase = 'multiple-sources';
41+
let dirname = 'test-cases';
42+
43+
if (fs.existsSync(path.join(testDir, testCase, 'source1.css'))) {
44+
it('should ' + testCase.replace(/-/g, ' '), () => {
45+
hook({
46+
root: testDir,
47+
use: pipelines[dirname]
48+
});
49+
50+
let expectedTokens = JSON.parse(fs.readFileSync(path.join(testDir, testCase, 'expected.json'), 'utf-8'));
51+
let tokens1 = require(`${testDir}/${testCase}/source1.css`);
52+
let tokens2 = require(`${testDir}/${testCase}/source2.css`);
53+
let tokens = Object.assign({}, tokens1, tokens2);
54+
55+
equal(JSON.stringify(tokens), JSON.stringify(expectedTokens));
56+
});
57+
}
58+
});
4959
});

0 commit comments

Comments
 (0)