mirror of https://github.com/sveltejs/svelte
parent
36a0b717d4
commit
6f61b5d70d
@ -1,31 +1,18 @@
|
|||||||
import { update_expected } from "../update";
|
import { loadConfig, update_expected } from "../helpers";
|
||||||
|
|
||||||
|
export function sanitize(compiled){
|
||||||
|
return compiled.js.code.replace(/generated by Svelte v\d+\.\d+\.\d+(-\w+\.\d+)?/, 'generated by Svelte vX.Y.Z');
|
||||||
|
}
|
||||||
|
|
||||||
// this file will replace all the expected.js files with their _actual
|
// this file will replace all the expected.js files with their _actual
|
||||||
// equivalents. Only use it when you're sure that you haven't
|
// equivalents. Only use it when you're sure that you haven't
|
||||||
// broken anything!
|
// broken anything!
|
||||||
|
|
||||||
function loadConfig(file) {
|
update_expected(
|
||||||
try {
|
(compile, check, get_relative) =>
|
||||||
const resolved = require.resolve(file);
|
check(
|
||||||
delete require.cache[resolved];
|
"expected.js",
|
||||||
|
sanitize(compile(loadConfig(get_relative("_config.js")).options))
|
||||||
const config = require(resolved);
|
),
|
||||||
return config.default || config;
|
__dirname
|
||||||
} catch (err) {
|
);
|
||||||
if (err.code === "MODULE_NOT_FOUND") {
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
|
|
||||||
throw err;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
update_expected((compile, check, get_relative) => {
|
|
||||||
check(
|
|
||||||
"expected.js",
|
|
||||||
compile(loadConfig(get_relative("_config.js")).options).js.code.replace(
|
|
||||||
/generated by Svelte v\d+\.\d+\.\d+(-\w+\.\d+)?/,
|
|
||||||
"generated by Svelte vX.Y.Z"
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}, __dirname);
|
|
||||||
|
@ -1,19 +1,27 @@
|
|||||||
import { update_expected } from "../update";
|
import { update_expected } from "../update";
|
||||||
|
|
||||||
|
export function sanitize_ast(compiled){
|
||||||
|
return compiled.ast;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function sanitize_error(e){
|
||||||
|
return {
|
||||||
|
code: e.code,
|
||||||
|
message: e.message,
|
||||||
|
start: e.start,
|
||||||
|
pos: e.pos
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// this file will replace all the expected.js files with their _actual
|
// this file will replace all the expected.js files with their _actual
|
||||||
// equivalents. Only use it when you're sure that you haven't
|
// equivalents. Only use it when you're sure that you haven't
|
||||||
// broken anything!
|
// broken anything!
|
||||||
|
|
||||||
update_expected((compile, check) => {
|
update_expected((compile, check) => {
|
||||||
try {
|
try {
|
||||||
check("output.json", compile({ generate: false }).ast);
|
check("output.json", sanitize_ast(compile({ generate: false })));
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (e.name !== "ParseError") throw e;
|
if (e.name !== "ParseError") throw e;
|
||||||
check("error.json", {
|
check("error.json", sanitize_error(e));
|
||||||
code: e.code,
|
|
||||||
message: e.message,
|
|
||||||
start: e.start,
|
|
||||||
pos: e.pos,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}, __dirname);
|
}, __dirname);
|
||||||
|
Loading…
Reference in new issue