Skip to content

Commit

Permalink
Merge pull request #6 from akaSybe/3-fix-failing-ci
Browse files Browse the repository at this point in the history
fix: fixed tests
  • Loading branch information
akaSybe authored Apr 13, 2020
2 parents 2231917 + 86b5e6d commit d321731
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 15 deletions.
5 changes: 5 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"editor.formatOnSave": true,
"editor.renderWhitespace": "all",
"editor.rulers": [80, 100]
}
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 9 additions & 5 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import vm from "vm";
import fs from "fs";
import { dirname, resolve, relative, sep as pathSeperator } from "path";
import path from "path";

function wrapModuleExports(code) {
return `
Expand Down Expand Up @@ -39,8 +39,12 @@ export default function ssr(options = {}) {
return {
name: "svelte-ssr",
async generateBundle(config, bundle, isWrite) {
const destPath = relative("./", config.file);
const destDir = destPath.slice(0, destPath.indexOf(pathSeperator));
if (config.format !== "cjs") {
throw new Error("rollup-plugin-svelte-ssr can only be used with 'cjs'-format");
}

const destPath = path.relative("./", config.file);
const destDir = destPath.slice(0, destPath.indexOf(path.sep));

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

const destination = resolve(destDir, fileName);
fs.mkdirSync(dirname(destination), { recursive: true });
const destination = path.resolve(destDir, fileName);
fs.mkdirSync(path.dirname(destination), { recursive: true });
fs.writeFileSync(destination, pluginOptions.configureExport(html, css));

if (pluginOptions.skipEmit) {
Expand Down
13 changes: 4 additions & 9 deletions test/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,19 +192,15 @@ describe("plugin tests", () => {
skipEmit: true,
};

let error;
try {
await bundleWithRollup({
await expect(
bundleWithRollup({
format: "esm",
plugin,
pluginOptions,
testName: "it-throws-error-for-non-cjs-format",
output: "doesnt-matter.html",
});
} catch (e) {
error = e;
}
expect(error).toEqual(new Error("rollup-plugin-svelte-ssr can only be used with 'cjs'-format"));
}),
).rejects.toThrow(new Error("rollup-plugin-svelte-ssr can only be used with 'cjs'-format"));
});

it("should throw error if no filename option has been passed", async () => {
Expand All @@ -215,7 +211,6 @@ describe("plugin tests", () => {
let error;
try {
await bundleWithRollup({
format: "esm",
plugin,
pluginOptions,
testName: "it-throws-error-if-no-filename-passed",
Expand Down

0 comments on commit d321731

Please sign in to comment.