Skip to content
This repository was archived by the owner on Jun 24, 2024. It is now read-only.

Commit 47efd28

Browse files
author
Walker
committed
Increase test coverage to 100%, ensure it stays.
1 parent 4db27eb commit 47efd28

File tree

3 files changed

+55
-3
lines changed

3 files changed

+55
-3
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ tmp/**/*
66
.idea/**/*
77
*.iml
88
*.log
9+
coverage

package.json

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,17 @@
3838
"format":
3939
"prettier --write --single-quote --tab-width=4 lib/**/*.js test/**/*.js",
4040
"lint": "eslint .",
41-
"test": "jest"
41+
"test": "jest --coverage"
4242
},
43-
"files": ["lib"]
43+
"files": ["lib"],
44+
"jest": {
45+
"coverageThreshold": {
46+
"global": {
47+
"branches": 100,
48+
"functions": 100,
49+
"lines": 100,
50+
"statements": 100
51+
}
52+
}
53+
}
4454
}

test/writer.test.js

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
'use strict';
22

3-
/* global test, expect */
3+
/* global test, expect, beforeEach */
44

55
const path = require('path');
66
const { hasher } = require('asset-pipe-common');
77
const { identifyCssModule, bundleCssModule } = require('../lib/util.js');
88
const Writer = require('..');
99

10+
beforeEach(() => {
11+
jest.clearAllMocks();
12+
jest.resetModules();
13+
});
14+
1015
test('identifyCssModule(filePath)', async () => {
1116
expect.assertions(1);
1217
const filePath = path.join(__dirname, 'test-assets/my-module-1/main.css');
@@ -205,3 +210,39 @@ test('new Writer([filePath]) ensures valid filePaths provided in array', () => {
205210

206211
expect(result).toThrow();
207212
});
213+
214+
test('writer emits error', done => {
215+
expect.assertions(1);
216+
jest.mock('../lib/util.js', () => ({
217+
bundleCssModule () {
218+
throw new Error();
219+
},
220+
identifyCssModule () {
221+
throw new Error();
222+
},
223+
}));
224+
const Writer = require('..');
225+
const filePath = path.join(__dirname, 'test-assets/my-module-1/main.css');
226+
227+
const writer = new Writer(filePath);
228+
229+
writer.on('error', error => {
230+
expect(error).toBeInstanceOf(Error);
231+
done();
232+
});
233+
writer.on('data', () => {});
234+
});
235+
236+
test('new Writer() emits nothing but does not break', done => {
237+
const writer = new Writer();
238+
const items = [];
239+
240+
writer.on('data', item => {
241+
items.push(item);
242+
});
243+
244+
writer.on('end', () => {
245+
expect(items.length).toBe(0);
246+
done();
247+
});
248+
});

0 commit comments

Comments
 (0)