-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: split out rollup watching tests
- Loading branch information
Showing
4 changed files
with
314 additions
and
218 deletions.
There are no files selected for viewing
68 changes: 68 additions & 0 deletions
68
packages/rollup/test/__snapshots__/rollup-watch.test.js.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`/rollup.js watch mode should correctly add new css files 1`] = ` | ||
"/* packages/rollup/test/output/watch/new-file/one.css */ | ||
.mc54f12712_one { | ||
color: red; | ||
}" | ||
`; | ||
|
||
exports[`/rollup.js watch mode should correctly remove & re-add dependencies 1`] = ` | ||
"/* packages/rollup/test/output/watch/watch-changed/two.css */ | ||
.mcd26cbf72_two { | ||
color: red; | ||
} | ||
/* packages/rollup/test/output/watch/watch-changed/one.css */ | ||
.mc8f47b33e_one { | ||
color: red; | ||
}" | ||
`; | ||
|
||
exports[`/rollup.js watch mode should correctly remove & re-add dependencies 2`] = ` | ||
"/* packages/rollup/test/output/watch/watch-changed/two.css */ | ||
.mcd26cbf72_two { | ||
color: blue; | ||
} | ||
/* packages/rollup/test/output/watch/watch-changed/one.css */ | ||
.mc8f47b33e_one { | ||
color: red; | ||
}" | ||
`; | ||
|
||
exports[`/rollup.js watch mode should correctly update files within the dependency graph 1`] = ` | ||
"/* packages/rollup/test/output/watch/dep-graph/one.css */ | ||
.mca3136a1b_one { | ||
color: red; | ||
} | ||
/* packages/rollup/test/output/watch/dep-graph/two.css */ | ||
.mc6f857f1c_two { | ||
color: blue; | ||
}" | ||
`; | ||
|
||
exports[`/rollup.js watch mode should correctly update files within the dependency graph 2`] = ` | ||
"/* packages/rollup/test/output/watch/dep-graph/one.css */ | ||
.mca3136a1b_one { | ||
color: green; | ||
} | ||
/* packages/rollup/test/output/watch/dep-graph/two.css */ | ||
.mc6f857f1c_two { | ||
color: blue; | ||
}" | ||
`; | ||
|
||
exports[`/rollup.js watch mode should generate output 1`] = ` | ||
"/* packages/rollup/test/output/watch/change/watched.css */ | ||
.mc5f9237d4_one { | ||
color: red; | ||
}" | ||
`; | ||
|
||
exports[`/rollup.js watch mode should generate output 2`] = ` | ||
"/* packages/rollup/test/output/watch/change/watched.css */ | ||
.mc5f9237d4_two { | ||
color: blue; | ||
}" | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,245 @@ | ||
/* eslint consistent-return: off */ | ||
"use strict"; | ||
|
||
const fs = require("fs"); | ||
const path = require("path"); | ||
|
||
const dedent = require("dedent"); | ||
const shell = require("shelljs"); | ||
|
||
const output = path.resolve(__dirname, "./output/watch"); | ||
|
||
const read = require("test-utils/read.js")(output); | ||
const write = require("test-utils/write.js")(output); | ||
const exists = require("test-utils/exists.js")(__dirname); | ||
const watching = require("test-utils/rollup-watching.js"); | ||
|
||
const plugin = require("../rollup.js"); | ||
|
||
const assetFileNames = "assets/[name][extname]"; | ||
const format = "es"; | ||
const map = false; | ||
|
||
describe("/rollup.js", () => { | ||
describe("watch mode", () => { | ||
const { watch } = require("rollup"); | ||
let watcher; | ||
|
||
beforeAll(() => shell.rm("-rf", `${output}/*`)); | ||
afterEach(() => watcher.close()); | ||
|
||
it("should generate output", (done) => { | ||
// Create v1 of the files | ||
write(`/change/watched.css`, dedent(` | ||
.one { | ||
color: red; | ||
} | ||
`)); | ||
|
||
write(`/change/watched.js`, dedent(` | ||
import css from "./watched.css"; | ||
console.log(css); | ||
`)); | ||
|
||
// Start watching | ||
watcher = watch({ | ||
input : `${output}/change/watched.js`, | ||
output : { | ||
file : `${output}/change/watch-output.js`, | ||
format, | ||
assetFileNames, | ||
}, | ||
plugins : [ | ||
plugin({ | ||
map, | ||
}), | ||
], | ||
}); | ||
|
||
// Create v2 of the file after a bit | ||
setTimeout(() => { | ||
write(`./change/watched.css`, dedent(` | ||
.two { | ||
color: blue; | ||
} | ||
`)); | ||
}, 200); | ||
|
||
watcher.on("event", watching((builds) => { | ||
if(builds === 1) { | ||
expect(read("./change/assets/watch-output.css")).toMatchSnapshot(); | ||
|
||
// continue watching | ||
return; | ||
} | ||
|
||
expect(read("./change/assets/watch-output.css")).toMatchSnapshot(); | ||
|
||
return done(); | ||
})); | ||
}); | ||
|
||
it("should correctly update files within the dependency graph", (done) => { | ||
// Create v1 of the files | ||
write(`./dep-graph/one.css`, dedent(` | ||
.one { | ||
color: red; | ||
} | ||
`)); | ||
|
||
write(`./dep-graph/two.css`, dedent(` | ||
.two { | ||
composes: one from "./one.css"; | ||
color: blue; | ||
} | ||
`)); | ||
|
||
write(`./dep-graph/watch.js`, dedent(` | ||
import css from "./two.css"; | ||
console.log(css); | ||
`)); | ||
|
||
// Start watching | ||
watcher = watch({ | ||
input : require.resolve(path.join(output, "./dep-graph/watch.js")), | ||
output : { | ||
file : `${output}/dep-graph/watch-output.js`, | ||
format, | ||
assetFileNames, | ||
}, | ||
plugins : [ | ||
plugin({ | ||
map, | ||
}), | ||
], | ||
}); | ||
|
||
// Create v2 of the file after a bit | ||
setTimeout(() => { | ||
write(`./dep-graph/one.css`, dedent(` | ||
.one { | ||
color: green; | ||
} | ||
`)); | ||
}, 200); | ||
|
||
watcher.on("event", watching((builds) => { | ||
if(builds === 1) { | ||
expect(read("dep-graph/assets/watch-output.css")).toMatchSnapshot(); | ||
|
||
// continue watching | ||
return; | ||
} | ||
|
||
expect(read("dep-graph/assets/watch-output.css")).toMatchSnapshot(); | ||
|
||
return done(); | ||
})); | ||
}); | ||
|
||
it("should correctly add new css files", (done) => { | ||
// Create v1 of the files | ||
write(`./new-file/one.css`, dedent(` | ||
.one { | ||
color: red; | ||
} | ||
`)); | ||
|
||
write(`./new-file/watch.js`, dedent(` | ||
console.log("hello"); | ||
`)); | ||
|
||
// Start watching | ||
watcher = watch({ | ||
input : require.resolve(path.join(output, "./new-file/watch.js")), | ||
output : { | ||
file : `${output}/new-file/watch-output.js`, | ||
format, | ||
assetFileNames, | ||
}, | ||
plugins : [ | ||
plugin({ | ||
map, | ||
}), | ||
], | ||
}); | ||
|
||
// Create v2 of the file after a bit | ||
setTimeout(() => write(`./new-file/watch.js`, dedent(` | ||
import css from "./one.css"; | ||
console.log(css); | ||
`)), 200); | ||
|
||
watcher.on("event", watching((builds) => { | ||
if(builds === 1) { | ||
expect(exists("./new-file/assets/watch-output.css")).toBe(false); | ||
|
||
// continue watching | ||
return; | ||
} | ||
|
||
expect(read("./new-file/assets/watch-output.css")).toMatchSnapshot(); | ||
|
||
return done(); | ||
})); | ||
}); | ||
|
||
it("should correctly remove & re-add dependencies", (done) => { | ||
// Create v1 of the files | ||
write(`./watch-changed/one.css`, dedent(` | ||
.one { | ||
composes: two from "./two.css"; | ||
color: red; | ||
} | ||
`)); | ||
|
||
write(`./watch-changed/two.css`, dedent(` | ||
.two { | ||
color: red; | ||
} | ||
`)); | ||
|
||
write(`./watch-changed/watch.js`, dedent(` | ||
import css from "./one.css"; | ||
console.log("hello"); | ||
`)); | ||
|
||
// Start watching | ||
watcher = watch({ | ||
input : require.resolve(path.join(output, "./watch-changed/watch.js")), | ||
output : { | ||
file : `${output}/watch-changed/watch-output.js`, | ||
format, | ||
assetFileNames, | ||
}, | ||
plugins : [ | ||
plugin({ | ||
map, | ||
}), | ||
], | ||
}); | ||
|
||
// Create v2 of the file after a bit | ||
setTimeout(() => write(`./watch-changed/two.css`, dedent(` | ||
.two { | ||
color: blue; | ||
} | ||
`)), 200); | ||
|
||
watcher.on("event", watching((builds) => { | ||
if(builds === 1) { | ||
expect(read("./watch-changed/assets/watch-output.css")).toMatchSnapshot(); | ||
|
||
// continue watching | ||
return; | ||
} | ||
|
||
expect(read("./watch-changed/assets/watch-output.css")).toMatchSnapshot(); | ||
|
||
return done(); | ||
})); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.