Skip to content

Commit

Permalink
test: split out rollup watching tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tivac committed Jul 11, 2018
1 parent 073019c commit 79abef5
Show file tree
Hide file tree
Showing 4 changed files with 314 additions and 218 deletions.
68 changes: 68 additions & 0 deletions packages/rollup/test/__snapshots__/rollup-watch.test.js.snap
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;
}"
`;
49 changes: 0 additions & 49 deletions packages/rollup/test/__snapshots__/rollup.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -285,52 +285,3 @@ exports[`/rollup.js shouldn't over-remove files from an existing processor insta
}
"
`;
exports[`/rollup.js watch should correctly add new css files in watch mode when files change 1`] = `
"/* packages/rollup/test/output/one.css */
.mc19ef5610_one {
color: red;
}"
`;
exports[`/rollup.js watch should correctly update files within the dependency graph in watch mode when files change 1`] = `
"/* packages/rollup/test/output/one.css */
.mc19ef5610_one {
color: red;
}
/* packages/rollup/test/output/two.css */
.mc32dbcb4b_two {
color: blue;
}"
`;
exports[`/rollup.js watch should correctly update files within the dependency graph in watch mode when files change 2`] = `
"/* packages/rollup/test/output/one.css */
.mc19ef5610_one {
color: green;
}
/* packages/rollup/test/output/two.css */
.mc32dbcb4b_two {
color: blue;
}"
`;
exports[`/rollup.js watch should generate correct builds in watch mode when files change 1`] = `
"/* packages/rollup/test/output/watched.css */
.mc580619a9_one { color: red; }
/* packages/rollup/test/specimens/simple.css */
.mc12d71625_fooga {
color: red;
}"
`;
exports[`/rollup.js watch should generate correct builds in watch mode when files change 2`] = `
"/* packages/rollup/test/output/watched.css */
.mc580619a9_two { color: blue; }
/* packages/rollup/test/specimens/simple.css */
.mc12d71625_fooga {
color: red;
}"
`;
245 changes: 245 additions & 0 deletions packages/rollup/test/rollup-watch.test.js
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();
}));
});
});
});
Loading

0 comments on commit 79abef5

Please sign in to comment.