Skip to content

Commit 049d2d8

Browse files
committed
got that first test running
1 parent 25f3cc0 commit 049d2d8

File tree

3 files changed

+36
-29
lines changed

3 files changed

+36
-29
lines changed

src/file-system-loader.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,11 @@ const traceKeySorter = ( a, b ) => {
2020
};
2121

2222
export default class FileSystemLoader {
23-
constructor( root ) {
23+
constructor( root, plugins ) {
2424
this.root = root
2525
this.sources = {}
2626
this.importNr = 0
27+
this.core = new Core(plugins)
2728
}
2829

2930
fetch( _newPath, relativeTo, _trace ) {
@@ -35,7 +36,7 @@ export default class FileSystemLoader {
3536

3637
fs.readFile( fileRelativePath, "utf-8", ( err, source ) => {
3738
if ( err ) reject( err )
38-
Core.load( source, rootRelativePath, trace, this.fetch.bind( this ) )
39+
this.core.load( source, rootRelativePath, trace, this.fetch.bind( this ) )
3940
.then( ( { injectableSource, exportTokens } ) => {
4041
this.sources[trace] = injectableSource
4142
resolve( exportTokens )

src/index.js

+11-12
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,10 @@ import scope from 'postcss-modules-scope'
55

66
import Parser from './parser'
77

8-
export default {
9-
// These three plugins are aliased under this package for simplicity.
10-
localByDefault,
11-
extractImports,
12-
scope,
13-
14-
// The default set of plugins
15-
plugins: [
16-
localByDefault,
17-
extractImports,
18-
scope
19-
],
8+
export default class Core {
9+
constructor( plugins ) {
10+
this.plugins = plugins || Core.defaultPlugins
11+
}
2012

2113
load( sourceString, sourcePath, trace, pathFetcher ) {
2214
let parser = new Parser( pathFetcher, trace )
@@ -28,3 +20,10 @@ export default {
2820
} )
2921
}
3022
}
23+
24+
25+
// These three plugins are aliased under this package for simplicity.
26+
Core.localByDefault = localByDefault
27+
Core.extractImports = extractImports
28+
Core.scope = scope
29+
Core.defaultPlugins = [localByDefault, extractImports, scope]

test/test-cases.js

+22-15
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,26 @@ let normalize = ( str ) => {
99
return str.replace( /\r\n?/g, "\n" );
1010
}
1111

12-
describe( "test-cases", () => {
13-
let testDir = path.join( __dirname, "test-cases" )
14-
fs.readdirSync( testDir ).forEach( testCase => {
15-
if ( fs.existsSync( path.join( testDir, testCase, "source.css" ) ) ) {
16-
it( "should " + testCase.replace( /-/g, " " ), done => {
17-
let expected = normalize( fs.readFileSync( path.join( testDir, testCase, "expected.css" ), "utf-8" ) )
18-
let loader = new FileSystemLoader( testDir )
19-
let expectedTokens = JSON.parse( fs.readFileSync( path.join( testDir, testCase, "expected.json" ), "utf-8" ) )
20-
loader.fetch( `${testCase}/source.css`, "/" ).then( tokens => {
21-
assert.equal( loader.finalSource, expected )
22-
assert.equal( JSON.stringify( tokens ), JSON.stringify( expectedTokens ) )
23-
} ).then( done, done )
24-
} );
25-
}
12+
const pipelines = {
13+
"test-cases": undefined,
14+
"cssi": []
15+
}
16+
17+
Object.keys( pipelines ).forEach( dirname => {
18+
describe( dirname, () => {
19+
let testDir = path.join( __dirname, dirname )
20+
fs.readdirSync( testDir ).forEach( testCase => {
21+
if ( fs.existsSync( path.join( testDir, testCase, "source.css" ) ) ) {
22+
it( "should " + testCase.replace( /-/g, " " ), done => {
23+
let expected = normalize( fs.readFileSync( path.join( testDir, testCase, "expected.css" ), "utf-8" ) )
24+
let loader = new FileSystemLoader( testDir, pipelines[dirname] )
25+
let expectedTokens = JSON.parse( fs.readFileSync( path.join( testDir, testCase, "expected.json" ), "utf-8" ) )
26+
loader.fetch( `${testCase}/source.css`, "/" ).then( tokens => {
27+
assert.equal( loader.finalSource, expected )
28+
assert.equal( JSON.stringify( tokens ), JSON.stringify( expectedTokens ) )
29+
} ).then( done, done )
30+
} );
31+
}
32+
} );
2633
} );
27-
} );
34+
} )

0 commit comments

Comments
 (0)