Skip to content

Commit

Permalink
write compiled output to disk for easier inspection
Browse files Browse the repository at this point in the history
  • Loading branch information
Rich-Harris committed Dec 9, 2019
1 parent 46e6559 commit 41d955c
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ node_modules
/test/sourcemaps/samples/*/output.css.map
/yarn-error.log
_actual*.*
_output
/types

/site/cypress/screenshots/
Expand Down
14 changes: 14 additions & 0 deletions test/helpers.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as jsdom from 'jsdom';
import * as assert from 'assert';
import * as glob from 'tiny-glob/sync.js';
import * as path from 'path';
import * as fs from 'fs';
import * as colors from 'kleur';

Expand Down Expand Up @@ -237,3 +238,16 @@ export function useFakeTimers() {
}
};
}

export function mkdirp(dir) {
const parent = path.dirname(dir);
if (parent === dir) return;

mkdirp(parent);

try {
fs.mkdirSync(dir);
} catch (err) {
// do nothing
}
}
33 changes: 31 additions & 2 deletions test/runtime/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@ import * as path from "path";
import * as fs from "fs";
import { rollup } from 'rollup';
import * as virtual from 'rollup-plugin-virtual';
import * as glob from 'tiny-glob/sync.js';
import { clear_loops, flush, set_now, set_raf } from "../../internal";

import {
showOutput,
loadConfig,
loadSvelte,
env,
setupHtmlEqual
setupHtmlEqual,
mkdirp
} from "../helpers.js";

let svelte$;
Expand Down Expand Up @@ -90,6 +92,33 @@ describe("runtime", () => {

const window = env();

glob('**/*.svelte', { cwd }).forEach(file => {
if (file[0] === '_') return;

const dir = `${cwd}/_output/${hydrate ? 'hydratable' : 'normal'}`;
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
}
});

return Promise.resolve()
.then(() => {
// hack to support transition tests
Expand Down Expand Up @@ -195,7 +224,7 @@ describe("runtime", () => {
} else {
throw err;
}
}).catch(err => {
}).catch(err => {
failed.add(dir);
showOutput(cwd, compileOptions, compile); // eslint-disable-line no-console
throw err;
Expand Down

0 comments on commit 41d955c

Please sign in to comment.