Skip to content

Commit 8242689

Browse files
committedFeb 2, 2018
test(watch): linting && structure
1 parent a8921cc commit 8242689

File tree

8 files changed

+29
-21
lines changed

8 files changed

+29
-21
lines changed
 
File renamed without changes.
File renamed without changes.
File renamed without changes.

‎test/fixtures/watch/style.css

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
@import "./import";

‎test/fixtures/watch/watching/style.css

-1
This file was deleted.

‎test/helpers/compiler.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ module.exports = function compiler (fixture, config, options) {
3131
},
3232
plugins: [
3333
new webpack.optimize.CommonsChunkPlugin({
34-
name: ['runtime'],
34+
name: [ 'runtime' ],
3535
minChunks: Infinity
3636
})
3737
].concat(config.plugins || [])
@@ -46,7 +46,7 @@ module.exports = function compiler (fixture, config, options) {
4646
if (options.watch) {
4747
return new Promise((resolve, reject) => {
4848
const watcher = compiler.watch({}, (err, stats) => {
49-
options.watch(err, stats, (s) => {
49+
options.watch(err, stats, () => {
5050
watcher.close(resolve)
5151
})
5252
})

‎test/helpers/fs.js

+10-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
const path = require('path')
2-
const { readFile: _readFile, writeFile: _writeFile, unlink: _unlink } = require('fs')
32
const promisify = require('util.promisify')
43

4+
const {
5+
unlink: _unlink,
6+
readFile: _readFile,
7+
writeFile: _writeFile
8+
} = require('fs')
9+
510
const fs = {
611
readFile: promisify(_readFile),
712
writeFile: promisify(_writeFile),
@@ -12,18 +17,18 @@ function readFile (name) {
1217
const file = path.join(__dirname, '../fixtures', name)
1318

1419
return fs.readFile(file)
15-
.then(data => data.toString())
20+
.then((data) => data.toString())
1621
}
1722

18-
function writeFile (name, contents) {
23+
function writeFile (name, data) {
1924
const file = path.join(__dirname, '../fixtures', name)
2025

21-
return fs.writeFile(file, contents)
26+
return fs.writeFile(file, data)
2227
}
2328

2429
module.exports.copyFile = function copyFile (src, dest) {
2530
return readFile(src)
26-
.then(contents => writeFile(dest, contents))
31+
.then((data) => writeFile(dest, data))
2732
}
2833

2934
module.exports.deleteFile = function deleteFile (name) {

‎test/loader.test.js

+16-13
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,22 @@ describe('Loader', () => {
2525
describe('Watching', () => {
2626
describe('Dependencies', () => {
2727
const files = {
28-
syntaxError: "watch/watching/syntaxError.css",
29-
noSyntaxError: "watch/watching/noSyntaxError.css",
30-
changingFile: "watch/watching/styleDep.css"
28+
css: 'watch/index.css',
29+
error: 'watch/error.css',
30+
changed: 'watch/import.css'
3131
}
3232

33-
beforeEach(() => copyFile(files.noSyntaxError, files.changingFile))
33+
beforeEach(() => copyFile(files.css, files.changed))
3434

35-
afterEach(() => deleteFile(files.changingFile))
35+
afterEach(() => deleteFile(files.changed))
3636

3737
test('Error', () => {
3838
const config = {
3939
loader: {
4040
options: {
41-
plugins: [require("postcss-import")],
41+
plugins: [
42+
require('postcss-import')
43+
],
4244
}
4345
}
4446
}
@@ -50,15 +52,15 @@ describe('Loader', () => {
5052
expect(src).toMatchSnapshot()
5153
expect(err.length).toEqual(0)
5254

53-
return copyFile(files.syntaxError, files.changingFile)
55+
return copyFile(files.error, files.changed)
5456
},
5557
(stats) => {
5658
const { err, src } = loader(stats)
5759

5860
expect(src).toMatchSnapshot()
5961
expect(err.length).toEqual(1)
6062

61-
return copyFile(files.noSyntaxError, files.changingFile)
63+
return copyFile(files.css, files.changed)
6264
},
6365
(stats, close) => {
6466
const { err, src } = loader(stats)
@@ -69,18 +71,19 @@ describe('Loader', () => {
6971

7072
return close()
7173
}
72-
];
74+
]
7375

74-
var currentStep = 0
76+
let step = 0
7577

7678
const options = {
7779
watch (err, stats, close) {
78-
steps[currentStep](stats, close)
79-
currentStep++
80+
steps[step](stats, close)
81+
82+
step++
8083
}
8184
}
8285

83-
return webpack('watch/watching/index.js', config, options)
86+
return webpack('watch/index.js', config, options)
8487
})
8588
})
8689
})

0 commit comments

Comments
 (0)
Please sign in to comment.