Skip to content

Commit 57b33bc

Browse files
wip(tests): minor refactoring
1 parent e981a2c commit 57b33bc

File tree

1 file changed

+52
-50
lines changed

1 file changed

+52
-50
lines changed

tests/testsTools.js

Lines changed: 52 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ const Path = require('path');
33
const puppeteer = require('puppeteer');
44
const mime = require('mime-types');
55

6-
76
const local = new URL('http://local/');
87

8+
const vueVersion = '3';
9+
910
async function createPage({ files }) {
1011

1112
async function getFile(url, encoding) {
@@ -100,74 +101,75 @@ afterAll(async () => {
100101
const defaultFiles = {
101102
'/vue3-sfc-loader.js': Fs.readFileSync(Path.join(__dirname, '../dist/vue3-sfc-loader.js'), { encoding: 'utf-8' }),
102103
'/vue': Fs.readFileSync(Path.join(__dirname, '../node_modules/vue/dist/vue.global.js'), { encoding: 'utf-8' }),
103-
'/boot.js': `
104104

105-
export default function boot({ options, createApp, mountApp }) {
105+
'/options.js': `
106+
107+
class HttpError extends Error {
108+
109+
constructor(url, res) {
106110
107-
mountApp( createApp(options) );
111+
super('HTTP error ' + res.statusCode);
112+
Error.captureStackTrace(this, this.constructor);
113+
114+
// enumerable: default false
115+
Object.defineProperties(this, {
116+
name: {
117+
value: this.constructor.name,
118+
},
119+
url: {
120+
value: url,
121+
},
122+
res: {
123+
value: res,
124+
},
125+
});
126+
}
108127
}
109128
110-
`,
111129
112-
'/index.html': `
113-
<!DOCTYPE html>
114-
<html><body>
115-
<script src="vue"></script>
116-
<script src="vue3-sfc-loader.js"></script>
117-
<script type="module">
130+
const options = {
118131
119-
import boot from '/boot.js'
132+
moduleCache: {
133+
vue: Vue
134+
},
120135
121-
class HttpError extends Error {
122-
123-
constructor(url, res) {
124-
125-
super('HTTP error ' + res.statusCode);
126-
Error.captureStackTrace(this, this.constructor);
127-
128-
// enumerable: default false
129-
Object.defineProperties(this, {
130-
name: {
131-
value: this.constructor.name,
132-
},
133-
url: {
134-
value: url,
135-
},
136-
res: {
137-
value: res,
138-
},
139-
});
140-
}
141-
}
136+
getFile(path) {
142137
138+
return fetch(path).then(res => res.ok ? res.text() : Promise.reject(new HttpError(path, res)));
139+
},
143140
144-
const options = {
141+
addStyle(textContent) {
145142
146-
moduleCache: {
147-
vue: Vue
148-
},
143+
const style = Object.assign(document.createElement('style'), { textContent });
144+
const ref = document.head.getElementsByTagName('style')[0] || null;
145+
document.head.insertBefore(style, ref);
146+
},
149147
150-
getFile(path) {
148+
log(type, ...args) {
151149
152-
return fetch(path).then(res => res.ok ? res.text() : Promise.reject(new HttpError(path, res)));
153-
},
150+
console[type](...args);
151+
}
152+
}
154153
155-
addStyle(textContent) {
154+
export default options;
155+
`,
156156

157-
const style = Object.assign(document.createElement('style'), { textContent });
158-
const ref = document.head.getElementsByTagName('style')[0] || null;
159-
document.head.insertBefore(style, ref);
160-
},
157+
'/boot.js': `
158+
export default ({ options, createApp, mountApp }) => mountApp( createApp(options) );
159+
`,
161160

162-
log(type, ...args) {
161+
'/index.html': `
162+
<!DOCTYPE html>
163+
<html><body>
164+
<script src="vue"></script>
165+
<script src="vue3-sfc-loader.js"></script>
166+
<script type="module">
163167
164-
console[type](...args);
165-
}
166-
}
168+
import boot from '/boot.js'
169+
import options from '/options.js'
167170
168171
const { loadModule } = window['vue3-sfc-loader'];
169172
170-
171173
function createApp(options) {
172174
173175
return Vue.createApp(Vue.defineAsyncComponent( () => loadModule('./component.vue', options) ));

0 commit comments

Comments
 (0)