Skip to content

Commit 9e1025f

Browse files
authored
Merge pull request webpack-contrib#141 from wrakky/test_restructure
Test restructure
2 parents da5a815 + 78f776b commit 9e1025f

18 files changed

+285
-240
lines changed

.travis.yml

+8
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
11
language: node_js
22

33
node_js:
4+
- 7
45
- 6
56
- 5
67
- 4
78

9+
env:
10+
- WEBPACK_VERSION=2
11+
- WEBPACK_VERSION=1
12+
813
matrix:
914
fast_finish: true
15+
16+
before_script:
17+
- npm install webpack@$WEBPACK_VERSION

package.json

+10-4
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,22 @@
2525
"object-hash": "^1.1.4"
2626
},
2727
"devDependencies": {
28+
"ava": "^0.17.0",
2829
"eslint": "^3.0.0",
2930
"eslint-friendly-formatter": "^2.0.4",
3031
"npmpub": "^3.0.1",
31-
"tape": "^4.0.0",
32-
"webpack": "^1.8.4"
32+
"webpack": "^2.2.0"
3333
},
3434
"scripts": {
3535
"lint": "eslint .",
36-
"tape": "tape test/*.js",
37-
"test": "npm run lint && npm run tape",
36+
"ava": "ava",
37+
"test": "npm run lint && npm run ava",
3838
"release": "npmpub"
39+
},
40+
"ava": {
41+
"files": [
42+
"test/*.js"
43+
],
44+
"verbose": true
3945
}
4046
}

test/autofix.js

+9-12
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,20 @@
1-
var test = require("tape")
1+
var test = require("ava")
22
var webpack = require("webpack")
3-
var assign = require("object-assign")
43
var conf = require("./utils/conf")
54
var fs = require("fs")
65

76
// clone the "fixable" file, so that we do not lose the original contents
87
// when the fixes are applied to disk
9-
test("setup", function(t) {
8+
test.before(function() {
109
fs
1110
.createReadStream("./test/fixtures/fixable.js")
1211
.pipe(fs.createWriteStream("./test/fixtures/fixable-clone.js"))
13-
14-
t.end()
1512
})
1613

17-
test("loader doesn't throw error if file ok after auto-fixing", function(t) {
18-
webpack(assign({},
19-
conf,
14+
test.cb("loader doesn't throw error if file ok after auto-fixing",
15+
function(t) {
16+
t.plan(2)
17+
webpack(conf(
2018
{
2119
entry: "./test/fixtures/fixable-clone.js",
2220
module: {
@@ -35,15 +33,14 @@ test("loader doesn't throw error if file ok after auto-fixing", function(t) {
3533
throw err
3634
}
3735
// console.log(stats.compilation.errors)
38-
t.notOk(stats.hasErrors(), "a good file doesn't give any error")
36+
t.false(stats.hasErrors(), "a good file doesn't give any error")
3937
// console.log(stats.compilation.warnings)
40-
t.notOk(stats.hasWarnings(), "a good file doesn't give any warning")
38+
t.false(stats.hasWarnings(), "a good file doesn't give any warning")
4139
t.end()
4240
})
4341
})
4442

4543
// remove the clone
46-
test("teardown", function(t) {
44+
test.after.always(function() {
4745
fs.unlinkSync("./test/fixtures/fixable-clone.js")
48-
t.end()
4946
})

test/error.js

+5-6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
var test = require("tape")
1+
var test = require("ava")
22
var webpack = require("webpack")
3-
var assign = require("object-assign")
43
var conf = require("./utils/conf")
54

6-
test("eslint-loader can return error if file is bad", function(t) {
7-
webpack(assign({},
8-
conf,
5+
test.cb("eslint-loader can return error if file is bad", function(t) {
6+
t.plan(1)
7+
webpack(conf(
98
{
109
entry: "./test/fixtures/error.js",
1110
}
@@ -16,7 +15,7 @@ test("eslint-loader can return error if file is bad", function(t) {
1615
}
1716

1817
// console.log(stats.compilation.errors)
19-
t.ok(
18+
t.true(
2019
stats.hasErrors(),
2120
"a file that contains eslint errors should return error"
2221
)

test/eslintignore.js

+10-11
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
1-
var test = require("tape")
1+
var test = require("ava")
22
var webpack = require("webpack")
3-
var assign = require("object-assign")
43
var conf = require("./utils/conf")
54

6-
test("eslint-loader ignores files present in .eslintignore", function(t) {
7-
webpack(assign({},
8-
conf,
5+
test.cb("eslint-loader ignores files present in .eslintignore", function(t) {
6+
t.plan(1)
7+
webpack(conf(
98
{
109
entry: "./test/fixtures/ignore.js",
11-
eslint: assign({}, conf.eslint, {
12-
// we want to enable ignore, so eslint will parse .eslintignore and
13-
// should skip the file specified above
14-
ignore: true,
15-
}),
10+
},
11+
{
12+
// we want to enable ignore, so eslint will parse .eslintignore and
13+
// should skip the file specified above
14+
ignore: true,
1615
}
1716
),
1817
function(err, stats) {
@@ -21,7 +20,7 @@ test("eslint-loader ignores files present in .eslintignore", function(t) {
2120
}
2221

2322
// console.log(stats.compilation.warnings)
24-
t.notOk(stats.hasWarnings(), "an ignored doesn't give a warning")
23+
t.false(stats.hasWarnings(), "an ignored doesn't give a warning")
2524
t.end()
2625
})
2726
})

test/force-emit-error.js

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
var test = require("ava")
2+
var webpack = require("webpack")
3+
var conf = require("./utils/conf")
4+
5+
test.cb("eslint-loader can force to emit error", function(t) {
6+
t.plan(2)
7+
webpack(conf(
8+
{
9+
entry: "./test/fixtures/warn.js",
10+
},
11+
{
12+
emitError: true,
13+
}
14+
),
15+
function(err, stats) {
16+
if (err) {
17+
throw err
18+
}
19+
20+
// console.log(stats.compilation.errors)
21+
t.true(stats.hasErrors(), "a file should return error if asked")
22+
// console.log(stats.compilation.warnings)
23+
t.false(
24+
stats.hasWarnings(),
25+
"a file should return no warning if error asked"
26+
)
27+
t.end()
28+
})
29+
})

test/force-emit-warning.js

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
var test = require("ava")
2+
var webpack = require("webpack")
3+
var conf = require("./utils/conf")
4+
5+
test.cb("eslint-loader can force to emit warning", function(t) {
6+
t.plan(2)
7+
webpack(conf(
8+
{
9+
entry: "./test/fixtures/error.js",
10+
},
11+
{
12+
emitWarning: true,
13+
}
14+
),
15+
function(err, stats) {
16+
if (err) {
17+
throw err
18+
}
19+
20+
// console.log(stats.compilation.warnings)
21+
t.true(stats.hasWarnings(), "a file should return warning if asked")
22+
// console.log(stats.compilation.errors)
23+
t.false(stats.hasErrors(), "a file should return no error if error asked")
24+
t.end()
25+
})
26+
})

test/force-emit.js

-53
This file was deleted.

test/formatter-custom.js

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/* eslint-disable no-console */
2+
var test = require("ava")
3+
var webpack = require("webpack")
4+
var conf = require("./utils/conf")
5+
6+
test.cb("eslint-loader can use custom formatter", function(t) {
7+
t.plan(1)
8+
webpack(conf(
9+
{
10+
entry: "./test/fixtures/error.js",
11+
},
12+
{
13+
formatter: require("eslint-friendly-formatter"),
14+
}
15+
),
16+
function(err, stats) {
17+
if (err) {
18+
throw err
19+
}
20+
21+
console.log("### Here is a example of another formatter")
22+
console.log(
23+
"# " +
24+
stats.compilation.errors[0].message
25+
.split("\n")
26+
.join("\n# ")
27+
)
28+
t.truthy(
29+
stats.compilation.errors[0].message,
30+
"webpack have some output with custom formatters"
31+
)
32+
t.end()
33+
})
34+
})

test/formatter-eslint.js

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/* eslint-disable no-console */
2+
var test = require("ava")
3+
var webpack = require("webpack")
4+
var conf = require("./utils/conf")
5+
6+
test.cb("eslint-loader can use eslint formatter", function(t) {
7+
t.plan(1)
8+
webpack(conf(
9+
{
10+
entry: "./test/fixtures/error.js",
11+
}
12+
),
13+
function(err, stats) {
14+
if (err) {
15+
throw err
16+
}
17+
18+
console.log("### Here is a example of the default formatter")
19+
console.log(
20+
"# " +
21+
stats.compilation.errors[0].message
22+
.split("\n")
23+
.join("\n# ")
24+
)
25+
t.truthy(stats.compilation.errors[0].message, "webpack have some output")
26+
t.end()
27+
})
28+
})

test/formatter-write.js

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/* eslint-disable no-console */
2+
var test = require("ava")
3+
var webpack = require("webpack")
4+
var conf = require("./utils/conf")
5+
var fs = require("fs")
6+
7+
test.cb("eslint-loader can be configured to write eslint results to a file",
8+
function(t) {
9+
t.plan(2)
10+
11+
var outputFilename = "outputReport.txt"
12+
var config = conf(
13+
{
14+
entry: "./test/fixtures/error.js",
15+
},
16+
{
17+
formatter: require("eslint/lib/formatters/checkstyle"),
18+
outputReport: {
19+
filePath: outputFilename,
20+
},
21+
}
22+
)
23+
24+
webpack(config,
25+
function(err, stats) {
26+
if (err) {
27+
throw err
28+
}
29+
30+
console.log("### Here is a the output of the formatter")
31+
console.log(
32+
"# " +
33+
stats.compilation.errors[0].message
34+
.split("\n")
35+
.join("\n# ")
36+
)
37+
38+
fs.readFile(config.output.path + outputFilename,
39+
"utf8", function(err, contents) {
40+
if (err) {
41+
t.fail("Expected file to have been created")
42+
}
43+
else {
44+
t.pass("File has been created")
45+
46+
t.is(stats.compilation.errors[0].message, contents,
47+
"File Contents should equal output")
48+
}
49+
50+
t.end()
51+
52+
})
53+
})
54+
})

0 commit comments

Comments
 (0)