Skip to content

Commit 2231917

Browse files
author
Shestakov Aleksandr
committed
test: additional tests
1 parent 28a731f commit 2231917

File tree

4 files changed

+48
-5
lines changed

4 files changed

+48
-5
lines changed

test/helpers.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export function resolveExpectedFile(testName) {
1313
return resolvePath(testName, "expected.html");
1414
}
1515

16-
export async function bundleWithRollup({ plugin, pluginOptions, testName, output }) {
16+
export async function bundleWithRollup({ plugin, pluginOptions, testName, output, format = "cjs" }) {
1717
const bundle = await rollup({
1818
input: resolvePath(testName, "App.svelte"),
1919
plugins: [
@@ -30,7 +30,7 @@ export async function bundleWithRollup({ plugin, pluginOptions, testName, output
3030
});
3131

3232
await bundle.write({
33-
format: "cjs",
33+
format,
3434
file: output,
3535
});
3636
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<div>Hello</div>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<div>Hello</div>

test/tests.js

+44-3
Original file line numberDiff line numberDiff line change
@@ -165,11 +165,11 @@ describe("plugin tests", () => {
165165
const pluginOptions = {
166166
fileName: ssrOutputFile,
167167
preprocessHtml: function(html) {
168-
return "<pre>replaced</pre>"
168+
return "<pre>replaced</pre>";
169169
},
170170
preprocessCss: function(css) {
171171
return "body { opacity: 0; }";
172-
}
172+
},
173173
};
174174

175175
await bundleWithRollup({ plugin, pluginOptions, testName, output: ssrBundleFile });
@@ -183,6 +183,47 @@ describe("plugin tests", () => {
183183
expectHtmlEqual(actual, expected);
184184

185185
// cleanup
186-
// await del(resolvePath(testName, "dist"));
186+
await del(resolvePath(testName, "dist"));
187+
});
188+
189+
it("should throw error for non-cjs format", async () => {
190+
const pluginOptions = {
191+
fileName: "doesnt-matter.html",
192+
skipEmit: true,
193+
};
194+
195+
let error;
196+
try {
197+
await bundleWithRollup({
198+
format: "esm",
199+
plugin,
200+
pluginOptions,
201+
testName: "it-throws-error-for-non-cjs-format",
202+
output: "doesnt-matter.html",
203+
});
204+
} catch (e) {
205+
error = e;
206+
}
207+
expect(error).toEqual(new Error("rollup-plugin-svelte-ssr can only be used with 'cjs'-format"));
208+
});
209+
210+
it("should throw error if no filename option has been passed", async () => {
211+
const pluginOptions = {
212+
skipEmit: true,
213+
};
214+
215+
let error;
216+
try {
217+
await bundleWithRollup({
218+
format: "esm",
219+
plugin,
220+
pluginOptions,
221+
testName: "it-throws-error-if-no-filename-passed",
222+
output: "doesnt-matter.html",
223+
});
224+
} catch (e) {
225+
error = e;
226+
}
227+
expect(error).toEqual(new Error("options.fileName should be string or function"));
187228
});
188229
});

0 commit comments

Comments
 (0)