Merge pull request #1930 from sveltejs/gh-1894

whitelist process, and fallback to globals
pull/1935/head
Rich Harris 6 years ago committed by GitHub
commit e7642db13d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -279,7 +279,7 @@ export default function dom(
const user_code = component.javascript || ( const user_code = component.javascript || (
component.ast.js.length === 0 && filtered_props.length > 0 component.ast.js.length === 0 && filtered_props.length > 0
? `let { ${filtered_props.map(x => x.name === x.as ? x.as : `${x.as}: ${x.name}`).join(', ')} } = $$props;` ? `let { ${filtered_props.map(x => x.name).join(', ')} } = $$props;`
: null : null
); );

@ -19,6 +19,7 @@ export default new Set([
'Object', 'Object',
'parseFloat', 'parseFloat',
'parseInt', 'parseInt',
'process',
'Promise', 'Promise',
'RegExp', 'RegExp',
'Set', 'Set',

@ -126,7 +126,9 @@ describe("runtime", () => {
global.window = window; global.window = window;
// Put the constructor on window for testing if (config.before_test) config.before_test();
// Put things we need on window for testing
window.SvelteComponent = SvelteComponent; window.SvelteComponent = SvelteComponent;
const target = window.document.querySelector("main"); const target = window.document.querySelector("main");
@ -208,6 +210,8 @@ describe("runtime", () => {
} }
flush(); flush();
if (config.after_test) config.after_test();
}); });
}); });
} }

@ -0,0 +1,11 @@
export default {
html: '<h1>Hello world!</h1>',
before_test() {
process.env.TMP_VAR = 'world';
},
after_test() {
delete process.env.TMP_VAR;
}
};

@ -114,6 +114,8 @@ describe("ssr", () => {
require("../../register")(compileOptions); require("../../register")(compileOptions);
try { try {
if (config.before_test) config.before_test();
const Component = require(`../runtime/samples/${dir}/main.html`).default; const Component = require(`../runtime/samples/${dir}/main.html`).default;
const { html } = Component.render(config.props, { const { html } = Component.render(config.props, {
store: (config.store !== true) && config.store store: (config.store !== true) && config.store
@ -124,6 +126,8 @@ describe("ssr", () => {
} else if (config.html) { } else if (config.html) {
assert.htmlEqual(html, config.html); assert.htmlEqual(html, config.html);
} }
if (config.after_test) config.after_test();
} catch (err) { } catch (err) {
if (config.error) { if (config.error) {
if (typeof config.error === 'function') { if (typeof config.error === 'function') {

Loading…
Cancel
Save