|
|
@ -4,13 +4,21 @@ import { env, normalizeHtml, svelte } from "../helpers.js";
|
|
|
|
|
|
|
|
|
|
|
|
function tryRequire(file) {
|
|
|
|
function tryRequire(file) {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
return require(file).default;
|
|
|
|
const mod = require(file);
|
|
|
|
|
|
|
|
return mod.default || mod;
|
|
|
|
} catch (err) {
|
|
|
|
} catch (err) {
|
|
|
|
if (err.code !== "MODULE_NOT_FOUND") throw err;
|
|
|
|
if (err.code !== "MODULE_NOT_FOUND") throw err;
|
|
|
|
return null;
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function normalizeWarning(warning) {
|
|
|
|
|
|
|
|
warning.frame = warning.frame.replace(/^\n/, '').replace(/^\t+/gm, '');
|
|
|
|
|
|
|
|
delete warning.filename;
|
|
|
|
|
|
|
|
delete warning.toString;
|
|
|
|
|
|
|
|
return warning;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
describe("css", () => {
|
|
|
|
describe("css", () => {
|
|
|
|
fs.readdirSync("test/css/samples").forEach(dir => {
|
|
|
|
fs.readdirSync("test/css/samples").forEach(dir => {
|
|
|
|
if (dir[0] === ".") return;
|
|
|
|
if (dir[0] === ".") return;
|
|
|
@ -28,19 +36,32 @@ describe("css", () => {
|
|
|
|
.readFileSync(`test/css/samples/${dir}/input.html`, "utf-8")
|
|
|
|
.readFileSync(`test/css/samples/${dir}/input.html`, "utf-8")
|
|
|
|
.replace(/\s+$/, "");
|
|
|
|
.replace(/\s+$/, "");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const expectedWarnings = (config.warnings || []).map(normalizeWarning);
|
|
|
|
|
|
|
|
const domWarnings = [];
|
|
|
|
|
|
|
|
const ssrWarnings = [];
|
|
|
|
|
|
|
|
|
|
|
|
const dom = svelte.compile(input, Object.assign(config, {
|
|
|
|
const dom = svelte.compile(input, Object.assign(config, {
|
|
|
|
format: 'iife',
|
|
|
|
format: 'iife',
|
|
|
|
name: 'SvelteComponent'
|
|
|
|
name: 'SvelteComponent',
|
|
|
|
|
|
|
|
onwarn: warning => {
|
|
|
|
|
|
|
|
domWarnings.push(warning);
|
|
|
|
|
|
|
|
}
|
|
|
|
}));
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
|
|
const ssr = svelte.compile(input, Object.assign(config, {
|
|
|
|
const ssr = svelte.compile(input, Object.assign(config, {
|
|
|
|
format: 'iife',
|
|
|
|
format: 'iife',
|
|
|
|
generate: 'ssr',
|
|
|
|
generate: 'ssr',
|
|
|
|
name: 'SvelteComponent'
|
|
|
|
name: 'SvelteComponent',
|
|
|
|
|
|
|
|
onwarn: warning => {
|
|
|
|
|
|
|
|
ssrWarnings.push(warning);
|
|
|
|
|
|
|
|
}
|
|
|
|
}));
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
|
|
assert.equal(dom.css, ssr.css);
|
|
|
|
assert.equal(dom.css, ssr.css);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assert.deepEqual(domWarnings.map(normalizeWarning), ssrWarnings.map(normalizeWarning));
|
|
|
|
|
|
|
|
assert.deepEqual(domWarnings.map(normalizeWarning), expectedWarnings);
|
|
|
|
|
|
|
|
|
|
|
|
fs.writeFileSync(`test/css/samples/${dir}/_actual.css`, dom.css);
|
|
|
|
fs.writeFileSync(`test/css/samples/${dir}/_actual.css`, dom.css);
|
|
|
|
const expected = {
|
|
|
|
const expected = {
|
|
|
|
html: read(`test/css/samples/${dir}/expected.html`),
|
|
|
|
html: read(`test/css/samples/${dir}/expected.html`),
|
|
|
|