Skip to content

Commit 86b5e6d

Browse files
author
Shestakov Aleksandr
committed
fix: fixed tests
fix #3
1 parent 2231917 commit 86b5e6d

File tree

4 files changed

+19
-15
lines changed

4 files changed

+19
-15
lines changed

.vscode/settings.json

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"editor.formatOnSave": true,
3+
"editor.renderWhitespace": "all",
4+
"editor.rulers": [80, 100]
5+
}

package-lock.json

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/index.js

+9-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import vm from "vm";
22
import fs from "fs";
3-
import { dirname, resolve, relative, sep as pathSeperator } from "path";
3+
import path from "path";
44

55
function wrapModuleExports(code) {
66
return `
@@ -39,8 +39,12 @@ export default function ssr(options = {}) {
3939
return {
4040
name: "svelte-ssr",
4141
async generateBundle(config, bundle, isWrite) {
42-
const destPath = relative("./", config.file);
43-
const destDir = destPath.slice(0, destPath.indexOf(pathSeperator));
42+
if (config.format !== "cjs") {
43+
throw new Error("rollup-plugin-svelte-ssr can only be used with 'cjs'-format");
44+
}
45+
46+
const destPath = path.relative("./", config.file);
47+
const destDir = destPath.slice(0, destPath.indexOf(path.sep));
4448

4549
Object.keys(bundle).forEach(async key => {
4650
const entry = bundle[key];
@@ -82,8 +86,8 @@ export default function ssr(options = {}) {
8286
? pluginOptions.fileName(entry)
8387
: pluginOptions.fileName;
8488

85-
const destination = resolve(destDir, fileName);
86-
fs.mkdirSync(dirname(destination), { recursive: true });
89+
const destination = path.resolve(destDir, fileName);
90+
fs.mkdirSync(path.dirname(destination), { recursive: true });
8791
fs.writeFileSync(destination, pluginOptions.configureExport(html, css));
8892

8993
if (pluginOptions.skipEmit) {

test/tests.js

+4-9
Original file line numberDiff line numberDiff line change
@@ -192,19 +192,15 @@ describe("plugin tests", () => {
192192
skipEmit: true,
193193
};
194194

195-
let error;
196-
try {
197-
await bundleWithRollup({
195+
await expect(
196+
bundleWithRollup({
198197
format: "esm",
199198
plugin,
200199
pluginOptions,
201200
testName: "it-throws-error-for-non-cjs-format",
202201
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"));
202+
}),
203+
).rejects.toThrow(new Error("rollup-plugin-svelte-ssr can only be used with 'cjs'-format"));
208204
});
209205

210206
it("should throw error if no filename option has been passed", async () => {
@@ -215,7 +211,6 @@ describe("plugin tests", () => {
215211
let error;
216212
try {
217213
await bundleWithRollup({
218-
format: "esm",
219214
plugin,
220215
pluginOptions,
221216
testName: "it-throws-error-if-no-filename-passed",

0 commit comments

Comments
 (0)