@@ -28,8 +28,6 @@ describe('loader', function() {
28
28
loader . call ( {
29
29
cacheable : cacheableSpy ,
30
30
callback : callbackSpy ,
31
- emitWarn : function ( warning ) { } ,
32
- emitError : function ( e ) { } ,
33
31
filename : fileName ,
34
32
query,
35
33
} , fileContents , null ) ;
@@ -40,7 +38,7 @@ describe('loader', function() {
40
38
}
41
39
42
40
43
- it ( 'should compile good ' ,
41
+ it ( 'should compile' ,
44
42
testLoader ( 'test/fixtures/good.html' , function ( err , code , map ) {
45
43
expect ( err ) . not . to . exist ;
46
44
@@ -50,65 +48,119 @@ describe('loader', function() {
50
48
) ;
51
49
52
50
53
- it ( 'should compile bad' ,
54
- testLoader ( 'test/fixtures/bad.html' , function ( err , code , map , context ) {
51
+ describe ( 'error handling' , function ( ) {
55
52
56
- expect ( err ) . to . exist ;
53
+ it ( 'should handle parse error' ,
54
+ testLoader ( 'test/fixtures/parse-error.html' , function ( err , code , map , context ) {
57
55
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
- ) ;
56
+ expect ( err ) . to . exist ;
64
57
65
- expect ( code ) . not . to . exist ;
66
- expect ( map ) . not . to . exist ;
67
- } )
68
- ) ;
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
+ ) ;
69
64
65
+ expect ( code ) . not . to . exist ;
66
+ expect ( map ) . not . to . exist ;
67
+ } )
68
+ ) ;
70
69
71
- it ( 'should compile with import / ES2015 features' ,
72
- testLoader ( 'test/fixtures/es2015.html' , function ( err , code , map ) {
73
- expect ( err ) . not . to . exist ;
74
70
75
- expect ( code ) . to . exist ;
76
- expect ( map ) . to . exist ;
71
+ it ( 'should handle wrong export' ,
72
+ testLoader ( 'test/fixtures/export-error.html' , function ( err , code , map , context ) {
77
73
78
- // es2015 statements remain
79
- expect ( code ) . to . contain ( 'import { hello } from \'./utils\';' ) ;
80
- expect ( code ) . to . contain ( 'data() {' ) ;
81
- } )
82
- ) ;
74
+ expect ( err ) . to . exist ;
83
75
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
+ ) ;
84
85
85
- it ( 'should compile Component with with nesting' ,
86
- testLoader ( 'test/fixtures/parent.html' , function ( err , code , map ) {
87
- expect ( err ) . not . to . exist ;
86
+ expect ( code ) . not . to . exist ;
87
+ expect ( map ) . not . to . exist ;
88
+ } )
89
+ ) ;
88
90
89
- // es2015 statements remain
90
- expect ( code ) . to . contain ( 'import Nested from \'./nested\';' ) ;
91
91
92
- expect ( code ) . to . exist ;
93
- expect ( map ) . to . exist ;
94
- } )
95
- ) ;
92
+ it ( 'should validation error' ,
93
+ testLoader ( 'test/fixtures/validation-error.html' , function ( err , code , map , context ) {
96
94
95
+ expect ( err ) . to . exist ;
97
96
98
- it ( 'should compile Component to CJS if requested' ,
99
- testLoader ( 'test/fixtures/good.html' , function ( err , code , map ) {
100
- expect ( err ) . not . to . exist ;
101
- expect ( code ) . to . contain ( 'module.exports = SvelteComponent;' ) ;
102
- } , { format : 'cjs' } )
103
- ) ;
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
+ ) ;
104
106
107
+ expect ( code ) . not . to . exist ;
108
+ expect ( map ) . not . to . exist ;
109
+ } )
110
+ ) ;
105
111
106
- it ( 'should compile Component to UMD if requested' ,
107
- testLoader ( 'test/fixtures/good.html' , function ( err , code , map ) {
108
- expect ( err ) . not . to . exist ;
109
- expect ( code ) . to . contain ( '(global.FooComponent = factory());' ) ;
110
- } , { format : 'umd' , name : 'FooComponent' } )
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
+ } ) ;
112
164
113
165
} ) ;
114
166
0 commit comments