Skip to content

Commit

Permalink
failing test for #1254
Browse files Browse the repository at this point in the history
  • Loading branch information
Rich-Harris committed Mar 18, 2018
1 parent ffa45dd commit 4cb8eff
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 9 deletions.
23 changes: 14 additions & 9 deletions test/runtime/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@ import {
spaces
} from "../helpers.js";

let svelte$;
let svelte;

let compileOptions = null;
let compile = null;

function getName(filename) {
const base = path.basename(filename).replace(".html", "");
Expand All @@ -25,15 +27,16 @@ function getName(filename) {

describe("runtime", () => {
before(() => {
svelte = loadSvelte(true);
svelte$ = loadSvelte(true);
svelte = loadSvelte(false);

require.extensions[".html"] = function(module, filename) {
const options = Object.assign(
{ filename, name: getName(filename), format: 'cjs' },
compileOptions
);

const { code } = svelte.compile(fs.readFileSync(filename, "utf-8"), options);
const { code } = compile(fs.readFileSync(filename, "utf-8"), options);

return module._compile(code, filename);
};
Expand All @@ -58,6 +61,8 @@ describe("runtime", () => {
throw new Error('skipping test, already failed');
}

compile = (config.preserveIdentifiers ? svelte : svelte$).compile;

const cwd = path.resolve(`test/runtime/samples/${dir}`);
global.document.title = '';

Expand All @@ -75,7 +80,7 @@ describe("runtime", () => {
`test/runtime/samples/${dir}/main.html`,
"utf-8"
);
const { code } = svelte.compile(source, compileOptions);
const { code } = compile(source, compileOptions);
const startIndex = code.indexOf("function create_main_fragment"); // may change!
if (startIndex === -1) throw new Error("missing create_main_fragment");
const endIndex = code.lastIndexOf("export default");
Expand All @@ -95,7 +100,7 @@ describe("runtime", () => {
if (err.frame) {
console.error(chalk.red(err.frame)); // eslint-disable-line no-console
}
showOutput(cwd, { shared, format: 'cjs', store: !!compileOptions.store }, svelte); // eslint-disable-line no-console
showOutput(cwd, { shared, format: 'cjs', store: !!compileOptions.store }, svelte$); // eslint-disable-line no-console
throw err;
}
}
Expand Down Expand Up @@ -140,7 +145,7 @@ describe("runtime", () => {
try {
SvelteComponent = require(`./samples/${dir}/main.html`);
} catch (err) {
showOutput(cwd, { shared, format: 'cjs', hydratable: hydrate, store: !!compileOptions.store }, svelte); // eslint-disable-line no-console
showOutput(cwd, { shared, format: 'cjs', hydratable: hydrate, store: !!compileOptions.store }, svelte$); // eslint-disable-line no-console
throw err;
}

Expand Down Expand Up @@ -198,12 +203,12 @@ describe("runtime", () => {
config.error(assert, err);
} else {
failed.add(dir);
showOutput(cwd, { shared, format: 'cjs', hydratable: hydrate, store: !!compileOptions.store }, svelte); // eslint-disable-line no-console
showOutput(cwd, { shared, format: 'cjs', hydratable: hydrate, store: !!compileOptions.store }, svelte$); // eslint-disable-line no-console
throw err;
}
})
.then(() => {
if (config.show) showOutput(cwd, { shared, format: 'cjs', hydratable: hydrate, store: !!compileOptions.store }, svelte);
if (config.show) showOutput(cwd, { shared, format: 'cjs', hydratable: hydrate, store: !!compileOptions.store }, svelte$);
});
});
}
Expand All @@ -216,7 +221,7 @@ describe("runtime", () => {
});

it("fails if options.target is missing in dev mode", () => {
const { code } = svelte.compile(`<div></div>`, {
const { code } = svelte$.compile(`<div></div>`, {
format: "iife",
name: "SvelteComponent",
dev: true
Expand All @@ -232,7 +237,7 @@ describe("runtime", () => {
});

it("fails if options.hydrate is true but the component is non-hydratable", () => {
const { code } = svelte.compile(`<div></div>`, {
const { code } = svelte$.compile(`<div></div>`, {
format: "iife",
name: "SvelteComponent",
dev: true
Expand Down
25 changes: 25 additions & 0 deletions test/runtime/samples/deconflict-elements-indexes/_config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
export default {
solo: true,
show: true,

html: `
<div>
<i>one</i>
</div>
`,

preserveIdentifiers: true,

test(assert, component, target) {
const { tagList } = component.get();
tagList.push('two');
component.set({ tagList });

assert.htmlEqual(target.innerHTML, `
<div>
<i>one</i>
<i>two</i>
</div>
`);
}
};
24 changes: 24 additions & 0 deletions test/runtime/samples/deconflict-elements-indexes/main.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<div>
{{#each tagList as tag, i}}
<i on:click='remove(i)'>
{{tag}}
</i>
{{/each}}
</div>

<script>
export default {
data() {
return {
inProgress: false,
tagList: ['one']
};
},

methods: {
remove(index) {
// ...
}
}
};
</script>

0 comments on commit 4cb8eff

Please sign in to comment.