Skip to content
This repository was archived by the owner on Sep 28, 2020. It is now read-only.

Test restructure #141

Merged
merged 3 commits into from
Feb 1, 2017
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
8 changes: 8 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
language: node_js

node_js:
- 7
- 6
- 5
- 4

env:
- WEBPACK_VERSION=2
- WEBPACK_VERSION=1

matrix:
fast_finish: true

before_script:
- npm install webpack@$WEBPACK_VERSION
14 changes: 10 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,22 @@
"object-hash": "^1.1.4"
},
"devDependencies": {
"ava": "^0.17.0",
"eslint": "^3.0.0",
"eslint-friendly-formatter": "^2.0.4",
"npmpub": "^3.0.1",
"tape": "^4.0.0",
"webpack": "^1.8.4"
"webpack": "^2.2.0"
},
"scripts": {
"lint": "eslint .",
"tape": "tape test/*.js",
"test": "npm run lint && npm run tape",
"ava": "ava",
"test": "npm run lint && npm run ava",
"release": "npmpub"
},
"ava": {
"files": [
"test/*.js"
],
"verbose": true
}
}
21 changes: 9 additions & 12 deletions test/autofix.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
var test = require("tape")
var test = require("ava")
var webpack = require("webpack")
var assign = require("object-assign")
var conf = require("./utils/conf")
var fs = require("fs")

// clone the "fixable" file, so that we do not lose the original contents
// when the fixes are applied to disk
test("setup", function(t) {
test.before(function() {
fs
.createReadStream("./test/fixtures/fixable.js")
.pipe(fs.createWriteStream("./test/fixtures/fixable-clone.js"))

t.end()
})

test("loader doesn't throw error if file ok after auto-fixing", function(t) {
webpack(assign({},
conf,
test.cb("loader doesn't throw error if file ok after auto-fixing",
function(t) {
t.plan(2)
webpack(conf(
{
entry: "./test/fixtures/fixable-clone.js",
module: {
Expand All @@ -35,15 +33,14 @@ test("loader doesn't throw error if file ok after auto-fixing", function(t) {
throw err
}
// console.log(stats.compilation.errors)
t.notOk(stats.hasErrors(), "a good file doesn't give any error")
t.false(stats.hasErrors(), "a good file doesn't give any error")
// console.log(stats.compilation.warnings)
t.notOk(stats.hasWarnings(), "a good file doesn't give any warning")
t.false(stats.hasWarnings(), "a good file doesn't give any warning")
t.end()
})
})

// remove the clone
test("teardown", function(t) {
test.after.always(function() {
fs.unlinkSync("./test/fixtures/fixable-clone.js")
t.end()
})
11 changes: 5 additions & 6 deletions test/error.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
var test = require("tape")
var test = require("ava")
var webpack = require("webpack")
var assign = require("object-assign")
var conf = require("./utils/conf")

test("eslint-loader can return error if file is bad", function(t) {
webpack(assign({},
conf,
test.cb("eslint-loader can return error if file is bad", function(t) {
t.plan(1)
webpack(conf(
{
entry: "./test/fixtures/error.js",
}
Expand All @@ -16,7 +15,7 @@ test("eslint-loader can return error if file is bad", function(t) {
}

// console.log(stats.compilation.errors)
t.ok(
t.true(
stats.hasErrors(),
"a file that contains eslint errors should return error"
)
Expand Down
21 changes: 10 additions & 11 deletions test/eslintignore.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
var test = require("tape")
var test = require("ava")
var webpack = require("webpack")
var assign = require("object-assign")
var conf = require("./utils/conf")

test("eslint-loader ignores files present in .eslintignore", function(t) {
webpack(assign({},
conf,
test.cb("eslint-loader ignores files present in .eslintignore", function(t) {
t.plan(1)
webpack(conf(
{
entry: "./test/fixtures/ignore.js",
eslint: assign({}, conf.eslint, {
// we want to enable ignore, so eslint will parse .eslintignore and
// should skip the file specified above
ignore: true,
}),
},
{
// we want to enable ignore, so eslint will parse .eslintignore and
// should skip the file specified above
ignore: true,
}
),
function(err, stats) {
Expand All @@ -21,7 +20,7 @@ test("eslint-loader ignores files present in .eslintignore", function(t) {
}

// console.log(stats.compilation.warnings)
t.notOk(stats.hasWarnings(), "an ignored doesn't give a warning")
t.false(stats.hasWarnings(), "an ignored doesn't give a warning")
t.end()
})
})
29 changes: 29 additions & 0 deletions test/force-emit-error.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
var test = require("ava")
var webpack = require("webpack")
var conf = require("./utils/conf")

test.cb("eslint-loader can force to emit error", function(t) {
t.plan(2)
webpack(conf(
{
entry: "./test/fixtures/warn.js",
},
{
emitError: true,
}
),
function(err, stats) {
if (err) {
throw err
}

// console.log(stats.compilation.errors)
t.true(stats.hasErrors(), "a file should return error if asked")
// console.log(stats.compilation.warnings)
t.false(
stats.hasWarnings(),
"a file should return no warning if error asked"
)
t.end()
})
})
26 changes: 26 additions & 0 deletions test/force-emit-warning.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
var test = require("ava")
var webpack = require("webpack")
var conf = require("./utils/conf")

test.cb("eslint-loader can force to emit warning", function(t) {
t.plan(2)
webpack(conf(
{
entry: "./test/fixtures/error.js",
},
{
emitWarning: true,
}
),
function(err, stats) {
if (err) {
throw err
}

// console.log(stats.compilation.warnings)
t.true(stats.hasWarnings(), "a file should return warning if asked")
// console.log(stats.compilation.errors)
t.false(stats.hasErrors(), "a file should return no error if error asked")
t.end()
})
})
53 changes: 0 additions & 53 deletions test/force-emit.js

This file was deleted.

34 changes: 34 additions & 0 deletions test/formatter-custom.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/* eslint-disable no-console */
var test = require("ava")
var webpack = require("webpack")
var conf = require("./utils/conf")

test.cb("eslint-loader can use custom formatter", function(t) {
t.plan(1)
webpack(conf(
{
entry: "./test/fixtures/error.js",
},
{
formatter: require("eslint-friendly-formatter"),
}
),
function(err, stats) {
if (err) {
throw err
}

console.log("### Here is a example of another formatter")
console.log(
"# " +
stats.compilation.errors[0].message
.split("\n")
.join("\n# ")
)
t.truthy(
stats.compilation.errors[0].message,
"webpack have some output with custom formatters"
)
t.end()
})
})
28 changes: 28 additions & 0 deletions test/formatter-eslint.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/* eslint-disable no-console */
var test = require("ava")
var webpack = require("webpack")
var conf = require("./utils/conf")

test.cb("eslint-loader can use eslint formatter", function(t) {
t.plan(1)
webpack(conf(
{
entry: "./test/fixtures/error.js",
}
),
function(err, stats) {
if (err) {
throw err
}

console.log("### Here is a example of the default formatter")
console.log(
"# " +
stats.compilation.errors[0].message
.split("\n")
.join("\n# ")
)
t.truthy(stats.compilation.errors[0].message, "webpack have some output")
t.end()
})
})
54 changes: 54 additions & 0 deletions test/formatter-write.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/* eslint-disable no-console */
var test = require("ava")
var webpack = require("webpack")
var conf = require("./utils/conf")
var fs = require("fs")

test.cb("eslint-loader can be configured to write eslint results to a file",
function(t) {
t.plan(2)

var outputFilename = "outputReport.txt"
var config = conf(
{
entry: "./test/fixtures/error.js",
},
{
formatter: require("eslint/lib/formatters/checkstyle"),
outputReport: {
filePath: outputFilename,
},
}
)

webpack(config,
function(err, stats) {
if (err) {
throw err
}

console.log("### Here is a the output of the formatter")
console.log(
"# " +
stats.compilation.errors[0].message
.split("\n")
.join("\n# ")
)

fs.readFile(config.output.path + outputFilename,
"utf8", function(err, contents) {
if (err) {
t.fail("Expected file to have been created")
}
else {
t.pass("File has been created")

t.is(stats.compilation.errors[0].message, contents,
"File Contents should equal output")
}

t.end()

})
})
})
Loading