Skip to content

Commit 60b9535

Browse files
committed
update test
1 parent 8fcf1d4 commit 60b9535

File tree

2 files changed

+43
-15
lines changed

2 files changed

+43
-15
lines changed

test/renderer/compiler.js

Lines changed: 42 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,49 @@ const test = require('ava');
33
const MemoryFs = require('memory-fs');
44
const Compiler = require('../../lib/renderer/compiler');
55

6+
test('Compiler.constructor(), CompilerOptions.global', async (t) => {
7+
const compiler = new Compiler(new MemoryFs(), { global: { APP_VERSION: '1.0.0' } });
8+
const vueOptions = await compiler.import(path.resolve(__dirname, '../vue_file/compiler/options_global.vue'));
9+
t.is(vueOptions.default.data().appVersion, '1.0.0');
10+
});
11+
12+
test('Compiler.constructor(), CompilerOptions.config', async (t) => {
13+
const webpackOptions = {
14+
module: { rules: [{ test: /\.jpg$/, use: { loader: 'null-loader' } }] },
15+
};
16+
const compiler = new Compiler(new MemoryFs(), { config: webpackOptions });
17+
const vueOptions = await compiler.import(path.resolve(__dirname, '../vue_file/compiler/options_config.vue'));
18+
t.is(vueOptions.default.name, 'config');
19+
});
20+
621
test('Compiler.import', async (t) => {
7-
const compiler = new Compiler(new MemoryFs(), { basePath: path.resolve(__dirname, '../vue_file') });
8-
const vueOptions = await compiler.import(path.resolve(__dirname, '../vue_file/store.vue'));
9-
t.truthy(vueOptions.default);
22+
const compiler = new Compiler(new MemoryFs());
23+
const vueOptions = await compiler.import(path.resolve(__dirname, '../vue_file/compiler/import.vue'));
24+
t.is(vueOptions.default.name, 'import');
1025
});
26+
27+
test('Compiler.import with es-next', async (t) => {
28+
const compiler = new Compiler(new MemoryFs());
29+
const vueOptions = await compiler.import(path.resolve(__dirname, '../vue_file/compiler/es_next.vue'));
30+
t.is(vueOptions.default.name, 'ESNext');
31+
});
32+
33+
test('Compiler.import when parallel', async (t) => {
34+
const compiler = new Compiler(new MemoryFs());
35+
const filePath = path.resolve(__dirname, '../vue_file/compiler/parallel.vue');
36+
const [file1, file2] = await Promise.all([
37+
compiler.import(filePath),
38+
compiler.import(filePath),
39+
]);
40+
t.is(file1, file2);
41+
t.is(Compiler.cacheMap.get(filePath).default.name, 'parallel');
42+
});
43+
1144
test('Compiler.load', async (t) => {
12-
const compiler = new Compiler(new MemoryFs(), { basePath: path.resolve(__dirname, '../vue_file') });
13-
const preloadFiles = [
14-
path.resolve(__dirname, '../vue_file/store.vue'),
15-
path.resolve(__dirname, '../vue_file/simple.vue'),
16-
];
17-
await compiler.load(preloadFiles);
18-
const startTime = Date.now();
19-
const vueOptions = await compiler.import(path.resolve(__dirname, '../vue_file/store.vue'));
20-
const endTime = Date.now();
21-
t.true(endTime - startTime < 10);
22-
t.truthy(vueOptions.default);
45+
const compiler = new Compiler(new MemoryFs());
46+
const path1 = path.resolve(__dirname, '../vue_file/compiler/load_1.vue');
47+
const path2 = path.resolve(__dirname, '../vue_file/compiler/load_2.vue');
48+
await compiler.load([path1, path2]);
49+
t.is(Compiler.cacheMap.get(path1).default.name, 'load1');
50+
t.is(Compiler.cacheMap.get(path2).default.name, 'load2');
2351
});

test/renderer/renderer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ test('renderer.renderToStream() should be ok', async (t) => {
7979
test('Renderer should be ok with store', async (t) => {
8080
const filePath = path.resolve(__dirname, '../vue_file/store.vue');
8181
const compiler = new Compiler(new MemoryFS());
82-
const renderer = new Renderer(compiler, { useStore: 'auto' });
82+
const renderer = new Renderer(compiler);
8383
renderer.on('error', e => t.fail(e));
8484
const string = await renderer.renderToString(filePath, { world: 'world!' });
8585
t.true(string.includes('hello world!'));

0 commit comments

Comments
 (0)