-
Notifications
You must be signed in to change notification settings - Fork 6
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
[#4] Set up the standard linter on CI #5
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,8 +4,10 @@ | |
"description": "file-loader that stores a map of original file names to file names with hashes in the compilation stats", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "env NODE_ENV=test mocha --require ./test/power_assert_loader.js test/basic.js test/integration.js --watch", | ||
"test-ci": "env NODE_ENV=test mocha --require ./test/power_assert_loader.js test/basic.js test/integration.js" | ||
"lint": "standard", | ||
"lint-fix": "standard --fix", | ||
"test": "npm run lint && env NODE_ENV=test mocha --require ./test/power_assert_loader.js test/basic.js test/integration.js --watch", | ||
"test-ci": "npm run lint && env NODE_ENV=test mocha --require ./test/power_assert_loader.js test/basic.js test/integration.js" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
|
@@ -29,6 +31,12 @@ | |
"rewire-test-helpers": "^0.2.0", | ||
"rimraf": "^2.4.3", | ||
"sinon": "^1.17.2", | ||
"standard": "^10.0.2", | ||
"webpack": "^1.12.2" | ||
}, | ||
"standard": { | ||
"env": [ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note that this applies the mocha env to all files being linted, including source (non-test) files. If we'd prefer, we can switch to using comments at the head of files There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it's ok, I doubt that |
||
"mocha" | ||
] | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,18 +5,18 @@ var staticFileLoaderKey = require('../').key | |
var webpack = require('webpack') | ||
var rmrf = require('rimraf') | ||
|
||
describe('integration tests', function() { | ||
beforeEach(function() { | ||
describe('integration tests', function () { | ||
beforeEach(function () { | ||
fs.symlinkSync(process.cwd(), path.join(process.cwd(), 'node_modules', 'static-file-loader')) | ||
}) | ||
|
||
afterEach(function(done) { | ||
afterEach(function (done) { | ||
fs.unlinkSync(path.join(process.cwd(), 'node_modules', 'static-file-loader')) | ||
rmrf(path.join(__dirname, 'dist'), done) | ||
}) | ||
|
||
context('when publicPath is specified', function() { | ||
it('stores files map in the compilation stats', function(done) { | ||
context('when publicPath is specified', function () { | ||
it('stores files map in the compilation stats', function (done) { | ||
var compiler = webpack({ | ||
context: __dirname, | ||
entry: './fixtures/index.js', | ||
|
@@ -26,24 +26,27 @@ describe('integration tests', function() { | |
publicPath: '/bundles' | ||
} | ||
}) | ||
compiler.run(function(err, stats) { | ||
compiler.run(function (err, stats) { | ||
if (err) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Standard style requires all errors be handled. I rethrow here, which will fail the tests, but I could instead call assert.fail if we prefer. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think that's enough 👍 |
||
throw err | ||
} | ||
var staticFiles = stats.compilation[staticFileLoaderKey] | ||
var fileNames = Object.keys(staticFiles) | ||
assert.deepEqual(fileNames.sort(), [ | ||
path.join(__dirname, 'fixtures', 'static', 'a.gif'), | ||
path.join(__dirname, 'fixtures', 'static', 'b.gif'), | ||
path.join(__dirname, 'fixtures', 'static', 'c.gif') | ||
]) | ||
fileNames.forEach(function(fileName) { | ||
fileNames.forEach(function (fileName) { | ||
assert(staticFiles[fileName].match(/\/bundles\/\w+.gif$/)) | ||
}) | ||
done() | ||
}) | ||
}) | ||
}) | ||
|
||
context('when publicPath is not specified', function() { | ||
it('stores files map in the compilation stats', function(done) { | ||
context('when publicPath is not specified', function () { | ||
it('stores files map in the compilation stats', function (done) { | ||
var compiler = webpack({ | ||
context: __dirname, | ||
entry: './fixtures/index.js', | ||
|
@@ -52,15 +55,18 @@ describe('integration tests', function() { | |
filename: 'bundle.js' | ||
} | ||
}) | ||
compiler.run(function(err, stats) { | ||
compiler.run(function (err, stats) { | ||
if (err) { | ||
throw err | ||
} | ||
var staticFiles = stats.compilation[staticFileLoaderKey] | ||
var fileNames = Object.keys(staticFiles) | ||
assert.deepEqual(fileNames.sort(), [ | ||
path.join(__dirname, 'fixtures', 'static', 'a.gif'), | ||
path.join(__dirname, 'fixtures', 'static', 'b.gif'), | ||
path.join(__dirname, 'fixtures', 'static', 'c.gif') | ||
]) | ||
fileNames.forEach(function(fileName) { | ||
fileNames.forEach(function (fileName) { | ||
assert(staticFiles[fileName].match(/\/\w+.gif$/)) | ||
}) | ||
done() | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will only run the linter one time, and then watch the unit tests. If we'd prefer, I can set up chokidar to run both tasks when files change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, maybe it's better to create separate
lint-watch
task? There is an amazing https://www.npmjs.com/package/eslint-watch that does this job well.As a side note. I think that the previous task naming is unfortunate. If I (or let's say CI) run
npm test
I expect to run it in a single mode. Maybe we should move watch mode tonpm run test-watch
for consistency sake?