From 41d955c23e3f25c413650510c7d3b90db5ee4f9b Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Mon, 9 Dec 2019 16:30:58 -0500 Subject: [PATCH] write compiled output to disk for easier inspection --- .gitignore | 1 + test/helpers.js | 14 ++++++++++++++ test/runtime/index.js | 33 +++++++++++++++++++++++++++++++-- 3 files changed, 46 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 053f905294..b0e6896dbe 100644 --- a/.gitignore +++ b/.gitignore @@ -23,6 +23,7 @@ node_modules /test/sourcemaps/samples/*/output.css.map /yarn-error.log _actual*.* +_output /types /site/cypress/screenshots/ diff --git a/test/helpers.js b/test/helpers.js index ff40ac5f79..2a03e0f436 100644 --- a/test/helpers.js +++ b/test/helpers.js @@ -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'; @@ -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 + } +} \ No newline at end of file diff --git a/test/runtime/index.js b/test/runtime/index.js index 60bd70a5d9..408fda40f4 100644 --- a/test/runtime/index.js +++ b/test/runtime/index.js @@ -3,6 +3,7 @@ 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 { @@ -10,7 +11,8 @@ import { loadConfig, loadSvelte, env, - setupHtmlEqual + setupHtmlEqual, + mkdirp } from "../helpers.js"; let svelte$; @@ -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 @@ -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;