@@ -32,37 +32,42 @@ describe('ember-cli-addon-tests (slow)', function() {
32
32
return request ( 'http://localhost:49741/assets/ts1.js' )
33
33
. then ( response => {
34
34
expect ( response . statusCode ) . to . equal ( 200 ) ;
35
- let parsed = esprima . parseScript ( response . body ) ;
36
- let bodyStatements = parsed . body
37
- . filter ( ( s ) => {
38
- return s . type === 'ExpressionStatement' ;
39
- } )
40
- . map ( ( s ) => s . expression )
41
- . filter ( ( s ) =>
42
- s . type === 'CallExpression' &&
43
- s . callee . type === 'Identifier' &&
44
- s . callee . name === 'define' &&
45
- s . arguments &&
46
- s . arguments [ 0 ] &&
47
- s . arguments [ 0 ] . type === 'Literal' &&
48
- s . arguments [ 0 ] . value === 'ts1/add' )
49
- . map ( ( s ) => s . arguments [ 2 ] . body . body ) [ 0 ] ;
50
35
51
- let functionDeclaration = bodyStatements . filter ( ( s ) => s . type === 'FunctionDeclaration' ) [ 0 ] ;
52
- expect ( functionDeclaration . id . name ) . to . equal ( 'add' ) ;
53
- expect ( functionDeclaration . body . body . length ) . to . equal ( 1 ) ;
54
- expect ( functionDeclaration . body . body [ 0 ] . type ) . to . equal ( 'ReturnStatement' ) ;
55
- expect ( functionDeclaration . params . length ) . to . equal ( 2 ) ;
56
- expect ( functionDeclaration . params [ 0 ] . name ) . to . equal ( 'a' ) ;
57
- expect ( functionDeclaration . params [ 1 ] . name ) . to . equal ( 'b' ) ;
36
+ let moduleBody = extractModuleBody ( response . body , 'ts1/add' ) ;
37
+ assertModuleBody ( moduleBody , `
38
+ "use strict";
58
39
59
- let returnArgument = functionDeclaration . body . body [ 0 ] . argument ;
60
- expect ( returnArgument . type ) . to . equal ( 'BinaryExpression' ) ;
61
- expect ( returnArgument . operator ) . to . equal ( '+' ) ;
62
- expect ( returnArgument . left . type ) . to . equal ( 'Identifier' ) ;
63
- expect ( returnArgument . left . name ) . to . equal ( 'a' ) ;
64
- expect ( returnArgument . right . type ) . to . equal ( 'Identifier' ) ;
65
- expect ( returnArgument . right . name ) . to . equal ( 'b' ) ;
40
+ Object.defineProperty(exports, "__esModule", {
41
+ value: true
42
+ });
43
+ exports.add = add;
44
+ function add(a, b) {
45
+ return a + b;
46
+ }
47
+ ` ) ;
66
48
} ) ;
67
49
} ) ;
68
50
} ) ;
51
+
52
+ function extractModuleBody ( responseJs , moduleName ) {
53
+ let parsed = esprima . parseScript ( responseJs ) ;
54
+ return parsed . body
55
+ . filter ( ( s ) => {
56
+ return s . type === 'ExpressionStatement' ;
57
+ } )
58
+ . map ( ( s ) => s . expression )
59
+ . filter ( ( s ) =>
60
+ s . type === 'CallExpression' &&
61
+ s . callee . type === 'Identifier' &&
62
+ s . callee . name === 'define' &&
63
+ s . arguments &&
64
+ s . arguments [ 0 ] &&
65
+ s . arguments [ 0 ] . type === 'Literal' &&
66
+ s . arguments [ 0 ] . value === moduleName )
67
+ . map ( ( s ) => s . arguments [ 2 ] . body ) [ 0 ] ;
68
+ }
69
+
70
+ function assertModuleBody ( actualParsed , expectedJs ) {
71
+ let expectedParsed = esprima . parseScript ( expectedJs ) ;
72
+ expect ( actualParsed . body ) . to . deep . equal ( expectedParsed . body ) ;
73
+ }
0 commit comments