Skip to content

test: replace helpers with @webpack-utilities/test #386

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 4, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,15 @@
"schema-utils": "^0.4.0"
},
"devDependencies": {
"jest": "^22.0.0",
"@webpack-utilities/test": "^1.0.0-alpha.0",
"jest": "^23.0.0",
"jsdoc-to-markdown": "^4.0.0",
"memory-fs": "^0.4.0",
"postcss-import": "^11.0.0",
"postcss-js": "^2.0.0",
"standard": "^11.0.0",
"standard-version": "^4.0.0",
"sugarss": "^1.0.0",
"util.promisify": "^1.0.0",
"webpack": "^3.0.0"
"webpack": "^4.0.0"
},
"scripts": {
"lint": "standard --env jest",
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
52 changes: 42 additions & 10 deletions test/Errors.test.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,63 @@
'use strict'

const webpack = require('./helpers/compiler')
const { loader } = require('./helpers/compilation')
const { webpack } = require('@webpack-utilities/test')

describe('Errors', () => {
test('Validation Error', () => {
const loader = require('../lib')
const config = {
loader: {
test: /\.css$/,
options: {
sourceMap: 1
}
}
}

return webpack('css/index.js', config).then((stats) => {
const { source } = stats.toJson().modules[1]

const error = () => loader.call({ query: { sourceMap: 1 } })
const error = () => eval(source)

expect(error).toThrow()
expect(error).toThrowErrorMatchingSnapshot()
expect(error).toThrow()

try {
error()
} catch ({ message }) {
message = message
.split('\n')
.slice(1)
.join('\n')

expect(message).toMatchSnapshot()
}
})
})

test('Syntax Error', () => {
const config = {
loader: {
test: /\.css$/,
options: {
parser: 'sugarss'
}
}
}

return webpack('css/index.js', config).then((stats) => {
const error = loader(stats).err
const { source } = stats.toJson().modules[1]

expect(error[0]).toMatchSnapshot()
const error = () => eval(source)

expect(error).toThrow()

try {
error()
} catch ({ message }) {
message = message
.split('\n')
.slice(1)
.join('\n')

expect(message).toMatchSnapshot()
}
})
})
})
6 changes: 3 additions & 3 deletions test/__snapshots__/Errors.test.js.snap
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Errors Syntax Error 1`] = `
[ModuleBuildError: Module build failed: Syntax Error
"Syntax Error

(1:3) Unexpected separator in property

> 1 | a { color: black }
 |  ^
 2 | 
]
"
`;

exports[`Errors Validation Error 1`] = `
"PostCSS Loader Invalid Options
"ValidationError: PostCSS Loader Invalid Options

options.sourceMap should be string,boolean
"
Expand Down
6 changes: 0 additions & 6 deletions test/__snapshots__/loader.test.js.snap
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Loader Default 1`] = `"module.exports = \\"a { color: black }\\\\n\\""`;

exports[`Loader Watching Dependencies Error 1`] = `"module.exports = \\"a { color: black }\\\\n\\""`;

exports[`Loader Watching Dependencies Error 2`] = `"throw new Error(\\"Module build failed: Syntax Error \\\\n\\\\n(1:5) Unknown word\\\\n\\\\n\\\\u001b[31m\\\\u001b[1m>\\\\u001b[22m\\\\u001b[39m\\\\u001b[90m 1 | \\\\u001b[39ma \\\\u001b[33m{\\\\u001b[39m color black \\\\u001b[33m}\\\\u001b[39m\\\\n \\\\u001b[90m | \\\\u001b[39m \\\\u001b[31m\\\\u001b[1m^\\\\u001b[22m\\\\u001b[39m\\\\n \\\\u001b[90m 2 | \\\\u001b[39m\\\\n\\");"`;

exports[`Loader Watching Dependencies Error 3`] = `"module.exports = \\"a { color: black }\\\\n\\""`;
1 change: 0 additions & 1 deletion test/fixtures/watch/error.css

This file was deleted.

1 change: 0 additions & 1 deletion test/fixtures/watch/index.css

This file was deleted.

3 changes: 0 additions & 3 deletions test/fixtures/watch/index.js

This file was deleted.

1 change: 0 additions & 1 deletion test/fixtures/watch/style.css

This file was deleted.

66 changes: 0 additions & 66 deletions test/helpers/compilation.js

This file was deleted.

63 changes: 0 additions & 63 deletions test/helpers/compiler.js

This file was deleted.

38 changes: 0 additions & 38 deletions test/helpers/fs.js

This file was deleted.

Loading