0
0
mirror of https://github.com/sveltejs/svelte.git synced 2024-12-01 17:30:59 +01:00

write ssr compiled output to disk for easier inspection

This commit is contained in:
Tan Li Hau 2019-12-23 10:58:27 +08:00 committed by Conduitry
parent 75b8d3fb21
commit 140bfd0ce2

View File

@ -1,13 +1,16 @@
import * as assert from "assert";
import * as fs from "fs";
import * as path from "path";
import * as glob from 'tiny-glob/sync.js';
import {
showOutput,
loadConfig,
loadSvelte,
setupHtmlEqual,
tryToLoadJson,
shouldUpdateExpected
shouldUpdateExpected,
mkdirp
} from "../helpers.js";
function tryToReadFile(file) {
@ -20,6 +23,7 @@ function tryToReadFile(file) {
}
const sveltePath = process.cwd().split('\\').join('/');
let compile = null;
describe("ssr", () => {
before(() => {
@ -28,6 +32,8 @@ describe("ssr", () => {
sveltePath
});
compile = loadSvelte(true).compile;
return setupHtmlEqual();
});
@ -142,6 +148,33 @@ describe("ssr", () => {
require("../../register")(compileOptions);
glob('**/*.svelte', { cwd }).forEach(file => {
if (file[0] === '_') return;
const dir = `${cwd}/_output/ssr`;
const out = `${dir}/${file.replace(/\.svelte$/, '.js')}`;
if (fs.existsSync(out)) {
fs.unlinkSync(out);
}
mkdirp(dir);
try {
const { js } = compile(
fs.readFileSync(`${cwd}/${file}`, 'utf-8'),
{
...compileOptions,
filename: file
}
);
fs.writeFileSync(out, js.code);
} catch (err) {
// do nothing
}
});
try {
if (config.before_test) config.before_test();