Skip to content

Commit

Permalink
test(watch): linting && structure
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-ciniawsky committed Feb 2, 2018
1 parent a8921cc commit 8242689
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 21 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions test/fixtures/watch/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@import "./import";
1 change: 0 additions & 1 deletion test/fixtures/watch/watching/style.css

This file was deleted.

4 changes: 2 additions & 2 deletions test/helpers/compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ module.exports = function compiler (fixture, config, options) {
},
plugins: [
new webpack.optimize.CommonsChunkPlugin({
name: ['runtime'],
name: [ 'runtime' ],
minChunks: Infinity
})
].concat(config.plugins || [])
Expand All @@ -46,7 +46,7 @@ module.exports = function compiler (fixture, config, options) {
if (options.watch) {
return new Promise((resolve, reject) => {
const watcher = compiler.watch({}, (err, stats) => {
options.watch(err, stats, (s) => {
options.watch(err, stats, () => {
watcher.close(resolve)
})
})
Expand Down
15 changes: 10 additions & 5 deletions test/helpers/fs.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
const path = require('path')
const { readFile: _readFile, writeFile: _writeFile, unlink: _unlink } = require('fs')
const promisify = require('util.promisify')

const {
unlink: _unlink,
readFile: _readFile,
writeFile: _writeFile
} = require('fs')

const fs = {
readFile: promisify(_readFile),
writeFile: promisify(_writeFile),
Expand All @@ -12,18 +17,18 @@ function readFile (name) {
const file = path.join(__dirname, '../fixtures', name)

return fs.readFile(file)
.then(data => data.toString())
.then((data) => data.toString())
}

function writeFile (name, contents) {
function writeFile (name, data) {
const file = path.join(__dirname, '../fixtures', name)

return fs.writeFile(file, contents)
return fs.writeFile(file, data)
}

module.exports.copyFile = function copyFile (src, dest) {
return readFile(src)
.then(contents => writeFile(dest, contents))
.then((data) => writeFile(dest, data))
}

module.exports.deleteFile = function deleteFile (name) {
Expand Down
29 changes: 16 additions & 13 deletions test/loader.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,22 @@ describe('Loader', () => {
describe('Watching', () => {
describe('Dependencies', () => {
const files = {
syntaxError: "watch/watching/syntaxError.css",
noSyntaxError: "watch/watching/noSyntaxError.css",
changingFile: "watch/watching/styleDep.css"
css: 'watch/index.css',
error: 'watch/error.css',
changed: 'watch/import.css'
}

beforeEach(() => copyFile(files.noSyntaxError, files.changingFile))
beforeEach(() => copyFile(files.css, files.changed))

afterEach(() => deleteFile(files.changingFile))
afterEach(() => deleteFile(files.changed))

test('Error', () => {
const config = {
loader: {
options: {
plugins: [require("postcss-import")],
plugins: [
require('postcss-import')
],
}
}
}
Expand All @@ -50,15 +52,15 @@ describe('Loader', () => {
expect(src).toMatchSnapshot()
expect(err.length).toEqual(0)

return copyFile(files.syntaxError, files.changingFile)
return copyFile(files.error, files.changed)
},
(stats) => {
const { err, src } = loader(stats)

expect(src).toMatchSnapshot()
expect(err.length).toEqual(1)

return copyFile(files.noSyntaxError, files.changingFile)
return copyFile(files.css, files.changed)
},
(stats, close) => {
const { err, src } = loader(stats)
Expand All @@ -69,18 +71,19 @@ describe('Loader', () => {

return close()
}
];
]

var currentStep = 0
let step = 0

const options = {
watch (err, stats, close) {
steps[currentStep](stats, close)
currentStep++
steps[step](stats, close)

step++
}
}

return webpack('watch/watching/index.js', config, options)
return webpack('watch/index.js', config, options)
})
})
})
Expand Down

0 comments on commit 8242689

Please sign in to comment.