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

Commit

Permalink
Migrate tests to use ava
Browse files Browse the repository at this point in the history
  • Loading branch information
peternewnham committed Jan 13, 2017
1 parent ca0af7a commit ee18cad
Show file tree
Hide file tree
Showing 17 changed files with 276 additions and 238 deletions.
11 changes: 9 additions & 2 deletions package.json
Expand Up @@ -25,6 +25,7 @@
"object-hash": "^1.1.4"
},
"devDependencies": {
"ava": "^0.17.0",
"eslint": "^3.0.0",
"eslint-friendly-formatter": "^2.0.4",
"npmpub": "^3.0.1",
Expand All @@ -33,8 +34,14 @@
},
"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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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()

})
})
})

0 comments on commit ee18cad

Please sign in to comment.