@@ -19,17 +19,17 @@ describe('loader', function() {
19
19
20
20
return function ( ) {
21
21
22
+ const fileContents = readFile ( fileName ) ;
23
+
22
24
const cacheableSpy = spy ( function ( ) { } ) ;
23
25
24
26
const callbackSpy = spy ( callback ) ;
25
27
26
- const fileContents = readFile ( fileName ) ;
27
-
28
28
loader . call ( {
29
29
cacheable : cacheableSpy ,
30
30
callback : callbackSpy ,
31
31
filename : fileName ,
32
- query : query ,
32
+ query,
33
33
} , fileContents , null ) ;
34
34
35
35
expect ( callbackSpy ) . to . have . been . called ;
@@ -38,7 +38,7 @@ describe('loader', function() {
38
38
}
39
39
40
40
41
- it ( 'should compile good ' ,
41
+ it ( 'should compile' ,
42
42
testLoader ( 'test/fixtures/good.html' , function ( err , code , map ) {
43
43
expect ( err ) . not . to . exist ;
44
44
@@ -48,57 +48,119 @@ describe('loader', function() {
48
48
) ;
49
49
50
50
51
- it ( 'should compile bad' ,
52
- testLoader ( 'test/fixtures/bad.html' , function ( err , code , map ) {
53
- expect ( err ) . to . exist ;
51
+ describe ( 'error handling' , function ( ) {
54
52
55
- expect ( code ) . not . to . exist ;
56
- expect ( map ) . not . to . exist ;
57
- } )
58
- ) ;
53
+ it ( 'should handle parse error' ,
54
+ testLoader ( 'test/fixtures/parse-error.html' , function ( err , code , map , context ) {
59
55
56
+ expect ( err ) . to . exist ;
60
57
61
- it ( 'should compile with import / ES2015 features' ,
62
- testLoader ( 'test/fixtures/es2015.html' , function ( err , code , map ) {
63
- expect ( err ) . not . to . exist ;
58
+ expect ( err . message ) . to . eql (
59
+ 'Expected }}} (1:18)\n' +
60
+ '1: <p>Count: {{{count}}</p>\n' +
61
+ ' ^\n' +
62
+ '2: <button on:click=\'set({ count: count + 1 })\'>+1</button>'
63
+ ) ;
64
64
65
- expect ( code ) . to . exist ;
66
- expect ( map ) . to . exist ;
65
+ expect ( code ) . not . to . exist ;
66
+ expect ( map ) . not . to . exist ;
67
+ } )
68
+ ) ;
67
69
68
- // es2015 statements remain
69
- expect ( code ) . to . contain ( 'import { hello } from \'./utils\';' ) ;
70
- expect ( code ) . to . contain ( 'data() {' ) ;
71
- } )
72
- ) ;
73
70
71
+ it ( 'should handle wrong export' ,
72
+ testLoader ( 'test/fixtures/export-error.html' , function ( err , code , map , context ) {
74
73
75
- it ( 'should compile Component with with nesting' ,
76
- testLoader ( 'test/fixtures/parent.html' , function ( err , code , map ) {
77
- expect ( err ) . not . to . exist ;
74
+ expect ( err ) . to . exist ;
78
75
79
- // es2015 statements remain
80
- expect ( code ) . to . contain ( 'import Nested from \'./nested\';' ) ;
76
+ expect ( err . message ) . to . eql (
77
+ 'Unexpected token (5:7)\n' +
78
+ '3: <script>\n' +
79
+ '4: export {\n' +
80
+ '5: foo: \'BAR\'\n' +
81
+ ' ^\n' +
82
+ '6: };\n' +
83
+ '7: </script>'
84
+ ) ;
81
85
82
- expect ( code ) . to . exist ;
83
- expect ( map ) . to . exist ;
84
- } )
85
- ) ;
86
+ expect ( code ) . not . to . exist ;
87
+ expect ( map ) . not . to . exist ;
88
+ } )
89
+ ) ;
86
90
87
91
88
- it ( 'should compile Component to CJS if requested' ,
89
- testLoader ( 'test/fixtures/good.html' , function ( err , code , map ) {
90
- expect ( err ) . not . to . exist ;
91
- expect ( code ) . to . contain ( 'module.exports = SvelteComponent;' ) ;
92
- } , { format : 'cjs' } )
93
- ) ;
92
+ it ( 'should validation error' ,
93
+ testLoader ( 'test/fixtures/validation-error.html' , function ( err , code , map , context ) {
94
94
95
+ expect ( err ) . to . exist ;
95
96
96
- it ( 'should compile Component to UMD if requested' ,
97
- testLoader ( 'test/fixtures/good.html' , function ( err , code , map ) {
98
- expect ( err ) . not . to . exist ;
99
- expect ( code ) . to . contain ( '(global.FooComponent = factory());' ) ;
100
- } , { format : 'umd' , name : 'FooComponent' } )
101
- ) ;
97
+ expect ( err . message ) . to . eql (
98
+ 'Computed properties can be function expressions or arrow function expressions (6:11)\n' +
99
+ '4: export default {\n' +
100
+ '5: computed: {\n' +
101
+ '6: foo: \'BAR\'\n' +
102
+ ' ^\n' +
103
+ '7: }\n' +
104
+ '8: };'
105
+ ) ;
106
+
107
+ expect ( code ) . not . to . exist ;
108
+ expect ( map ) . not . to . exist ;
109
+ } )
110
+ ) ;
111
+
112
+ } ) ;
113
+
114
+
115
+ describe ( 'ES2015 features' , function ( ) {
116
+
117
+ it ( 'should keep imports / methods' ,
118
+ testLoader ( 'test/fixtures/es2015.html' , function ( err , code , map ) {
119
+ expect ( err ) . not . to . exist ;
120
+
121
+ expect ( code ) . to . exist ;
122
+ expect ( map ) . to . exist ;
123
+
124
+ // es2015 statements remain
125
+ expect ( code ) . to . contain ( 'import { hello } from \'./utils\';' ) ;
126
+ expect ( code ) . to . contain ( 'data() {' ) ;
127
+ } )
128
+ ) ;
129
+
130
+
131
+ it ( 'should keep nested Component import' ,
132
+ testLoader ( 'test/fixtures/parent.html' , function ( err , code , map ) {
133
+ expect ( err ) . not . to . exist ;
134
+
135
+ // es2015 statements remain
136
+ expect ( code ) . to . contain ( 'import Nested from \'./nested\';' ) ;
137
+
138
+ expect ( code ) . to . exist ;
139
+ expect ( map ) . to . exist ;
140
+ } )
141
+ ) ;
142
+
143
+ } ) ;
144
+
145
+
146
+ describe ( 'configuration via query' , function ( ) {
147
+
148
+ it ( 'should configure CommonJS output' ,
149
+ testLoader ( 'test/fixtures/good.html' , function ( err , code , map ) {
150
+ expect ( err ) . not . to . exist ;
151
+ expect ( code ) . to . contain ( 'module.exports = SvelteComponent;' ) ;
152
+ } , { format : 'cjs' } )
153
+ ) ;
154
+
155
+
156
+ it ( 'should configure named UMD output' ,
157
+ testLoader ( 'test/fixtures/good.html' , function ( err , code , map ) {
158
+ expect ( err ) . not . to . exist ;
159
+ expect ( code ) . to . contain ( '(global.FooComponent = factory());' ) ;
160
+ } , { format : 'umd' , name : 'FooComponent' } )
161
+ ) ;
162
+
163
+ } ) ;
102
164
103
165
} ) ;
104
166
0 commit comments