Skip to content

Commit

Permalink
test: failing test for svelte reprocessing
Browse files Browse the repository at this point in the history
This can occur when using modular-css-svelte and modular-css-rollup together in rollup's watch mode.
  • Loading branch information
tivac committed Aug 1, 2018
1 parent a45117b commit 2162a06
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 0 deletions.
28 changes: 28 additions & 0 deletions packages/svelte/test/__snapshots__/svelte.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -292,4 +292,32 @@ exports[`/svelte.js should ignore files without <style> blocks 1`] = `
exports[`/svelte.js should ignore files without <style> blocks 2`] = `""`;
exports[`/svelte.js should remove files before reprocessing in case they changed 1`] = `
"
<div class=\\"source\\">Source</div><script>
import css from \\"./source.css\\";
</script>"
`;
exports[`/svelte.js should remove files before reprocessing in case they changed 2`] = `
"/* packages/svelte/test/output/source.css */
.source {
color: red;
}"
`;
exports[`/svelte.js should remove files before reprocessing in case they changed 3`] = `
"
<div class=\\"source\\">Source</div><script>
import css from \\"./source.css\\";
</script>"
`;
exports[`/svelte.js should remove files before reprocessing in case they changed 4`] = `
"/* packages/svelte/test/output/source.css */
.source {
color: blue;
}"
`;
exports[`/svelte.js should throw on both <style> and <link> in one file 1`] = `"modular-css-svelte: use <style> OR <link>, but not both"`;
47 changes: 47 additions & 0 deletions packages/svelte/test/svelte.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"use strict";

const fs = require("fs");
const path = require("path");

const svelte = require("svelte");
const dedent = require("dedent");
Expand Down Expand Up @@ -131,4 +132,50 @@ describe("/svelte.js", () => {
)
).rejects.toThrowErrorMatchingSnapshot();
});

it("should remove files before reprocessing in case they changed", async () => {
// V1 of files
fs.writeFileSync(path.resolve(__dirname, "./output/source.html"), dedent(`
<link rel="stylesheet" href="./source.css" />
<div class="{css.source}">Source</div>
`));

fs.writeFileSync(path.resolve(__dirname, "./output/source.css"), dedent(`
.source {
color: red;
}
`));

const filename = require.resolve(`./output/source.html`);
const { processor, preprocess } = plugin({ namer });

let processed = await svelte.preprocess(
fs.readFileSync(filename, "utf8"),
Object.assign({}, preprocess, { filename })
);

expect(processed.toString()).toMatchSnapshot();

let output = await processor.output();

expect(output.css).toMatchSnapshot();

// V2 of CSS
fs.writeFileSync(path.resolve(__dirname, "./output/source.css"), dedent(`
.source {
color: blue;
}
`));

processed = await svelte.preprocess(
fs.readFileSync(filename, "utf8"),
Object.assign({}, preprocess, { filename })
);

expect(processed.toString()).toMatchSnapshot();

output = await processor.output();

expect(output.css).toMatchSnapshot();
});
});

0 comments on commit 2162a06

Please sign in to comment.