@@ -3,21 +3,49 @@ const test = require('ava');
33const MemoryFs = require ( 'memory-fs' ) ;
44const 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 : / \. j p g $ / , 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+
621test ( '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+
1144test ( '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} ) ;
0 commit comments