Skip to content

Commit dd9707b

Browse files
wip(tests): test custom blocks
1 parent 57741d8 commit dd9707b

File tree

2 files changed

+57
-1
lines changed

2 files changed

+57
-1
lines changed

tests/basic.test.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,48 @@ test('should handle missing dynamic import', async () => {
407407
});
408408

409409

410+
test.only('should handle custom blocks asynchronously', async () => {
411+
412+
const { page, output } = await createPage({
413+
files: {
414+
...defaultFiles,
415+
'/component.vue': `
416+
<script>
417+
export default {
418+
mounted() {
419+
420+
console.log( this.$options.bazComponentProperty );
421+
}
422+
}
423+
</script>
424+
425+
<foo>bar</foo>
426+
427+
`,
428+
'/optionsOverride.js': `
429+
430+
export default options => {
431+
432+
options.customBlockHandler = async (block, filename, options) => {
433+
434+
console.log(block.type, block.content);
435+
436+
return async (component) => {
437+
438+
component.bazComponentProperty = 'baz';
439+
}
440+
}
441+
}
442+
`
443+
}
444+
});
445+
446+
expect(output.filter(e => e.type === 'log').map(e => e.content).flat().join(',')).toBe('foo,bar,baz');
447+
448+
await page.close();
449+
});
450+
451+
410452
/*
411453
xtest('should not hang on cycles', async () => {
412454

tests/testsTools.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,13 +100,22 @@ afterAll(async () => {
100100
const defaultFiles = {
101101
'/vue3-sfc-loader.js': Fs.readFileSync(Path.join(__dirname, '../dist/vue3-sfc-loader.js'), { encoding: 'utf-8' }),
102102
'/vue': Fs.readFileSync(Path.join(__dirname, '../node_modules/vue/dist/vue.global.js'), { encoding: 'utf-8' }),
103+
'/optionsOverride.js': `
104+
export default () => {};
105+
`,
106+
'/appOverride.js': `
107+
export default () => {};
108+
`,
103109
'/index.html': `
104110
<!DOCTYPE html>
105111
<html><body>
106112
<div id="app"></div>
107113
<script src="vue"></script>
108114
<script src="vue3-sfc-loader.js"></script>
109-
<script>
115+
<script type="module">
116+
117+
import optionsOverride from '/optionsOverride.js'
118+
import appOverride from '/appOverride.js'
110119
111120
class HttpError extends Error {
112121
@@ -155,8 +164,13 @@ const defaultFiles = {
155164
}
156165
}
157166
167+
optionsOverride(options);
168+
158169
const { loadModule } = window['vue3-sfc-loader'];
159170
const app = Vue.createApp(Vue.defineAsyncComponent( () => loadModule('./component.vue', options) ));
171+
172+
appOverride(app);
173+
160174
app.mount('#app');
161175
162176
//window._done && window._done();

0 commit comments

Comments
 (0)