Skip to content

Commit 9f68c70

Browse files
test: refactor
1 parent da6ca2a commit 9f68c70

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+585
-242
lines changed

lib/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,13 @@ const SyntaxError = require('./Error')
4040
* @return {cb} cb Result
4141
*/
4242
module.exports = function loader (css, map) {
43-
const cb = this.async()
44-
const file = this.resourcePath
45-
4643
const options = loaderUtils.getOptions(this) || {}
4744

4845
validateOptions(require('./options.json'), options, 'PostCSS Loader')
4946

47+
const cb = this.async()
48+
const file = this.resourcePath
49+
5050
const sourceMap = options.sourceMap
5151

5252
Promise.resolve().then(() => {

package.json

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,25 +17,29 @@
1717
},
1818
"devDependencies": {
1919
"coveralls": "^2.0.0",
20-
"fs-extra": "^3.0.0",
2120
"jest": "^21.0.0",
2221
"jsdoc-to-markdown": "^3.0.0",
22+
"memory-fs": "^0.4.0",
2323
"postcss-js": "^1.0.0",
2424
"standard": "^10.0.0",
2525
"standard-version": "^4.0.0",
2626
"sugarss": "^1.0.0",
2727
"webpack": "^3.0.0"
2828
},
2929
"scripts": {
30-
"clean": "rm -rf dmd jsdoc-api jest* coverage test/builds",
30+
"clean": "rm -rf dmd jest* coverage jsdoc-api test/results",
3131
"lint": "standard",
3232
"docs": "jsdoc2md lib/index.js > LOADER.md",
33-
"pretest": "npm run lint && npm run test:build",
34-
"test": "jest",
35-
"test:build": "node test/webpack.build.js",
33+
"postdocs": "npm run clean",
34+
"test": "jest --verbose --coverage",
3635
"posttest": "npm run clean",
3736
"release": "standard-version"
3837
},
38+
"jest": {
39+
"collectCoverageFrom": [
40+
"lib/*.js"
41+
]
42+
},
3943
"standard": {
4044
"env": {
4145
"jest": true

test/Errors.test.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
'use strict'
2+
3+
const webpack = require('./helpers/compiler')
4+
const { loader } = require('./helpers/compilation')
5+
6+
describe('Errors', () => {
7+
test('Validation Error', () => {
8+
const loader = require('../lib')
9+
10+
const error = () => loader.call({ query: { sourceMap: 1 } })
11+
12+
expect(error).toThrow()
13+
expect(error).toThrowErrorMatchingSnapshot()
14+
})
15+
16+
test('Syntax Error', () => {
17+
const config = {
18+
loader: {
19+
options: {
20+
parser: 'sugarss'
21+
}
22+
}
23+
}
24+
25+
return webpack('css/index.js', config).then((stats) => {
26+
const error = loader(stats).err
27+
28+
expect(error[0]).toMatchSnapshot()
29+
})
30+
})
31+
})
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`Errors Syntax Error 1`] = `
4+
[ModuleBuildError: Module build failed: Syntax Error
5+
6+
(1:3) Unexpected separator in property
7+
8+
> 1 | a { color: black }
9+
 |  ^
10+
 2 | 
11+
]
12+
`;
13+
14+
exports[`Errors Validation Error 1`] = `
15+
"Validation Error
16+
17+
PostCSS Loader Invalid Options
18+
19+
options.sourceMap should be string,boolean
20+
"
21+
`;
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`Loader Default 1`] = `"module.exports = \\"a { color: black }\\\\n\\""`;

test/configs/config.config.js

Lines changed: 0 additions & 9 deletions
This file was deleted.

test/configs/config.js

Lines changed: 0 additions & 4 deletions
This file was deleted.

test/configs/error.config.js

Lines changed: 0 additions & 6 deletions
This file was deleted.

test/configs/error.js

Lines changed: 0 additions & 5 deletions
This file was deleted.

test/configs/exec.config.js

Lines changed: 0 additions & 6 deletions
This file was deleted.

test/configs/exec.js

Lines changed: 0 additions & 4 deletions
This file was deleted.

test/configs/export.config.js

Lines changed: 0 additions & 8 deletions
This file was deleted.

test/configs/export.js

Lines changed: 0 additions & 4 deletions
This file was deleted.

test/configs/jss.config.js

Lines changed: 0 additions & 6 deletions
This file was deleted.

test/configs/jss.js

Lines changed: 0 additions & 4 deletions
This file was deleted.

test/configs/map.config.js

Lines changed: 0 additions & 9 deletions
This file was deleted.

test/configs/map.js

Lines changed: 0 additions & 4 deletions
This file was deleted.

test/configs/options.config.js

Lines changed: 0 additions & 8 deletions
This file was deleted.

test/configs/options.js

Lines changed: 0 additions & 5 deletions
This file was deleted.

test/configs/parser-object.config.js

Lines changed: 0 additions & 8 deletions
This file was deleted.

test/configs/parser-object.js

Lines changed: 0 additions & 4 deletions
This file was deleted.

test/configs/parser-string.config.js

Lines changed: 0 additions & 6 deletions
This file was deleted.

test/configs/parser-string.js

Lines changed: 0 additions & 4 deletions
This file was deleted.

test/configs/plugins.config.js

Lines changed: 0 additions & 8 deletions
This file was deleted.

test/configs/plugins.fn.config.js

Lines changed: 0 additions & 8 deletions
This file was deleted.

test/configs/plugins.fn.js

Lines changed: 0 additions & 4 deletions
This file was deleted.

test/configs/plugins.js

Lines changed: 0 additions & 4 deletions
This file was deleted.

test/configs/sourceMap-inline.config.js

Lines changed: 0 additions & 9 deletions
This file was deleted.

test/configs/sourceMap-inline.js

Lines changed: 0 additions & 4 deletions
This file was deleted.

test/configs/sourceMap-true.config.js

Lines changed: 0 additions & 9 deletions
This file was deleted.

test/configs/sourceMap-true.js

Lines changed: 0 additions & 4 deletions
This file was deleted.

test/configs/stringifier.config.js

Lines changed: 0 additions & 6 deletions
This file was deleted.

test/configs/stringifier.js

Lines changed: 0 additions & 4 deletions
This file was deleted.

test/configs/syntax.config.js

Lines changed: 0 additions & 6 deletions
This file was deleted.

test/configs/syntax.js

Lines changed: 0 additions & 4 deletions
This file was deleted.
File renamed without changes.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module.exports = (ctx) => ({
22
plugins: [
3-
ctx.options.plugin ? require('../../plugin')() : false
3+
ctx.options.plugin ? require('./plugin')() : false
44
]
55
})

test/fixtures/css/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import style from './style.css'
2+
3+
export default style
File renamed without changes.

test/fixtures/jss/exec/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import style from './style.exec.js'
2+
3+
export default style
File renamed without changes.

test/fixtures/jss/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import style from './style.js'
2+
3+
export default style
File renamed without changes.

test/fixtures/postcss.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module.exports = {
22
plugins: [
3-
require('../plugin')()
3+
require('./config/plugin')()
44
]
55
}

test/fixtures/sss/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import style from './style.sss'
2+
3+
export default style
File renamed without changes.

test/fixtures/style.css

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)