Skip to content

Commit 476a0ea

Browse files
committed
Merge pull request #11 from sullenor/better-coverage
Better coverage
2 parents ecabdc8 + f99013b commit 476a0ea

File tree

4 files changed

+30
-6
lines changed

4 files changed

+30
-6
lines changed

src/index.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@ import LocalByDefault from 'postcss-modules-local-by-default';
99
import Scope from 'postcss-modules-scope';
1010
import Parser from './parser';
1111

12+
const defaultRoot = process.cwd();
13+
const tokensByFile = {};
1214
let plugins = [LocalByDefault, ExtractImports, Scope];
13-
let rootDir;
15+
let root = defaultRoot;
1416

1517
/**
1618
* @param {string} sourceString The file content
@@ -28,8 +30,6 @@ function load(sourceString, sourcePath, trace, pathFetcher) {
2830
}
2931

3032
hook(filename => {
31-
const root = rootDir || dirname(filename);
32-
const tokensByFile = {};
3333
let importNr = 0;
3434

3535
const fetch = (_newPath, _relativeTo, _trace) => {
@@ -67,7 +67,7 @@ export default function configure(opts = {}) {
6767
? customPlugins
6868
: [LocalByDefault, ExtractImports, Scope];
6969

70-
if (opts.root && typeof opts.root === 'string') {
71-
rootDir = opts.root;
72-
}
70+
root = opts.root && typeof opts.root === 'string'
71+
? opts.root
72+
: defaultRoot;
7373
}

test/cases/simple/expected.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"localName": "_test_cases_simple_source__localName"
3+
}

test/cases/simple/source.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.localName
2+
{
3+
color: #369;
4+
}

test/index.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { equal } from 'assert';
2+
import { readFileSync } from 'fs';
3+
import { join } from 'path';
4+
import hook from '../src';
5+
6+
describe('css-modules-require-hook', () => {
7+
describe('without options', () => {
8+
before(hook);
9+
10+
it('should return tokens', () => {
11+
const expectedTokens = JSON.parse(readFileSync(join(__dirname, './cases/simple/expected.json'), 'utf8'));
12+
const tokens = require('./cases/simple/source.css');
13+
14+
equal(JSON.stringify(expectedTokens), JSON.stringify(tokens));
15+
});
16+
});
17+
});

0 commit comments

Comments
 (0)