-
-
Notifications
You must be signed in to change notification settings - Fork 211
fix(index): continue watching after dependency {Error}
#332
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
Changes from 3 commits
c7ccb95
ce7802e
d64b26e
b1b97d4
fe5a8b5
6a6968d
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 |
---|---|---|
@@ -1,3 +1,9 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`Loader Default 1`] = `"module.exports = \\"a { color: black }\\\\n\\""`; | ||
|
||
exports[`Loader Watching Deps After An Error Default 1`] = `"module.exports = \\"a { color: black }\\\\n\\""`; | ||
|
||
exports[`Loader Watching Deps After An Error Default 2`] = `"throw new Error(\\"Module build failed: Syntax Error \\\\n\\\\n(1:5) Unknown word\\\\n\\\\n\\\\u001b[31m\\\\u001b[1m>\\\\u001b[22m\\\\u001b[39m\\\\u001b[90m 1 | \\\\u001b[39ma \\\\u001b[33m{\\\\u001b[39m color black \\\\u001b[33m}\\\\u001b[39m\\\\n \\\\u001b[90m | \\\\u001b[39m \\\\u001b[31m\\\\u001b[1m^\\\\u001b[22m\\\\u001b[39m\\\\n \\\\u001b[90m 2 | \\\\u001b[39m\\\\n\\");"`; | ||
|
||
exports[`Loader Watching Deps After An Error Default 3`] = `"module.exports = \\"a { color: black }\\\\n\\""`; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import style from './style.css' | ||
|
||
export default style |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
a { color: black } |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
@import "./styleDep"; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
a { color black } |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,11 +43,21 @@ module.exports = function compiler (fixture, config, options) { | |
|
||
if (!options.emit) compiler.outputFileSystem = new MemoryFS() | ||
|
||
return new Promise((resolve, reject) => { | ||
return compiler.run((err, stats) => { | ||
if (err) reject(err) | ||
if (options.watching) { | ||
return new Promise((resolve, reject) => { | ||
const c = compiler.watch({}, (err, stats) => { | ||
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.
|
||
options.handler(err, stats, (s) => { | ||
c.close(resolve) | ||
}) | ||
}) | ||
}) | ||
} else { | ||
return new Promise((resolve, reject) => { | ||
return compiler.run((err, stats) => { | ||
if (err) reject(err) | ||
|
||
resolve(stats) | ||
resolve(stats) | ||
}) | ||
}) | ||
}) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
const path = require('path') | ||
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.
|
||
const { readFile, writeFile, unlink } = require('fs') | ||
const promisify = require('util.promisify') | ||
|
||
const rf = promisify(readFile) | ||
const wf = promisify(writeFile) | ||
const rm = promisify(unlink) | ||
|
||
function readCssFile (name) { | ||
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.
|
||
const fileName = path.join(__dirname, '../fixtures', name) | ||
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.
|
||
|
||
return rf(fileName) | ||
.then(c => c.toString()) | ||
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.
|
||
} | ||
|
||
function writeCssFile (name, contents) { | ||
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.
|
||
const fileName = path.join(__dirname, '../fixtures', name) | ||
|
||
return wf(fileName, contents) | ||
} | ||
|
||
module.exports.copyCssFile = function copyCssFile (src, dest) { | ||
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.
|
||
return readCssFile(src) | ||
.then(contents => writeCssFile(dest, contents)) | ||
} | ||
|
||
module.exports.deleteCssFile = function deleteCssFile (name) { | ||
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.
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. delete is a reserved keyword, want me to call the functions deleteFile, copyFile, etc? 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. Ooops 😛 yeah right... |
||
const fileName = path.join(__dirname, '../fixtures', name) | ||
|
||
return rm(fileName) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
|
||
const webpack = require('./helpers/compiler') | ||
const { loader } = require('./helpers/compilation') | ||
const { copyCssFile, deleteCssFile } = require('./helpers/fileChange'); | ||
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. const { copy, delete } = require('./helpers/fs') |
||
|
||
describe('Loader', () => { | ||
test('Default', () => { | ||
|
@@ -20,4 +21,62 @@ describe('Loader', () => { | |
expect(src).toMatchSnapshot() | ||
}) | ||
}) | ||
|
||
describe('Watching Deps After An Error', () => { | ||
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. describe('Watching', () => {
describe('Dependencies', () => {
test('Error', () => {
// ...
})
})
}) |
||
const files = { | ||
syntaxError: "css-watching/syntaxError.css", | ||
noSyntaxError: "css-watching/noSyntaxError.css", | ||
changingFile: "css-watching/styleDep.css" | ||
} | ||
|
||
beforeAll(() => copyCssFile(files.noSyntaxError, files.changingFile)) | ||
|
||
afterAll(() => deleteCssFile(files.changingFile)) | ||
|
||
test('Default', () => { | ||
const config = { | ||
loader: { | ||
options: { | ||
plugins: [require("postcss-import")], | ||
watching: true | ||
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. This should be 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. Good catch, it isn't needed at all since I'm calling .watch() on the compiler. |
||
} | ||
} | ||
} | ||
|
||
const testSteps = [ | ||
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.
|
||
(stats) => { | ||
const { err, src } = loader(stats) | ||
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.
|
||
expect(src).toMatchSnapshot() | ||
expect(err.length).toEqual(0) | ||
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.
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. For each element in |
||
return copyCssFile(files.syntaxError, files.changingFile) | ||
}, | ||
(stats) => { | ||
const { err, src } = loader(stats) | ||
expect(src).toMatchSnapshot() | ||
expect(err.length).toEqual(1) | ||
return copyCssFile(files.noSyntaxError, files.changingFile) | ||
}, | ||
(stats, close) => { | ||
const { err, src } = loader(stats) | ||
expect(src).toMatchSnapshot() | ||
expect(src).toEqual("module.exports = \"a { color: black }\\n\"") | ||
expect(err.length).toEqual(0) | ||
return close() | ||
} | ||
]; | ||
|
||
var currentStep = 0 | ||
|
||
const options = { | ||
watching: true, | ||
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. Either const options = {
watch (err, stats, close) {
// ...handling
}
} or const options = {
watch: {
handler (err, stats, close) { // ...handling }
}
} |
||
handler: (err, stats, close) => { | ||
testSteps[currentStep](stats, close) | ||
currentStep++ | ||
} | ||
} | ||
|
||
return webpack('css-watching/index.js', config, options) | ||
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.
|
||
}) | ||
}) | ||
|
||
}) |
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.