@@ -7,7 +7,6 @@ const { expect } = chai;
7
7
8
8
const fsp = require ( 'fs' ) . promises ;
9
9
const fse = require ( 'fs-extra' ) ;
10
- const proxyquire = require ( 'proxyquire' ) ;
11
10
const readConfiguration = require ( '../../../../lib/configuration/read' ) ;
12
11
13
12
describe ( 'test/unit/lib/configuration/read.test.js' , ( ) => {
@@ -58,7 +57,7 @@ describe('test/unit/lib/configuration/read.test.js', () => {
58
57
expect ( await readConfiguration ( configurationPath ) ) . to . deep . equal ( configuration ) ;
59
58
} ) ;
60
59
61
- it ( 'should read "serverless.js"' , async ( ) => {
60
+ it ( 'should read "serverless.js" as CJS ' , async ( ) => {
62
61
configurationPath = 'serverless.js' ;
63
62
const configuration = {
64
63
service : 'test-js' ,
@@ -68,23 +67,7 @@ describe('test/unit/lib/configuration/read.test.js', () => {
68
67
expect ( await readConfiguration ( configurationPath ) ) . to . deep . equal ( configuration ) ;
69
68
} ) ;
70
69
71
- it ( 'should read "serverless.ts"' , async ( ) => {
72
- await fse . ensureDir ( 'node_modules' ) ;
73
- try {
74
- await fsp . writeFile ( 'node_modules/ts-node.js' , 'module.exports.register = () => null;' ) ;
75
- configurationPath = 'serverless.ts' ;
76
- const configuration = {
77
- service : 'test-ts' ,
78
- provider : { name : 'aws' } ,
79
- } ;
80
- await fsp . writeFile ( configurationPath , `module.exports = ${ JSON . stringify ( configuration ) } ` ) ;
81
- expect ( await readConfiguration ( configurationPath ) ) . to . deep . equal ( configuration ) ;
82
- } finally {
83
- await fse . remove ( 'node_modules' ) ;
84
- }
85
- } ) ;
86
-
87
- it ( 'should read "serverless.cjs"' , async ( ) => {
70
+ it ( 'should read "serverless.cjs" as CJS' , async ( ) => {
88
71
configurationPath = 'serverless.cjs' ;
89
72
const configuration = {
90
73
service : 'test-js' ,
@@ -94,7 +77,7 @@ describe('test/unit/lib/configuration/read.test.js', () => {
94
77
expect ( await readConfiguration ( configurationPath ) ) . to . deep . equal ( configuration ) ;
95
78
} ) ;
96
79
97
- it ( 'should read "serverless.mjs"' , async ( ) => {
80
+ it ( 'should read "serverless.mjs" as ESM ' , async ( ) => {
98
81
configurationPath = 'serverless.mjs' ;
99
82
const configuration = {
100
83
service : 'test-js' ,
@@ -104,10 +87,9 @@ describe('test/unit/lib/configuration/read.test.js', () => {
104
87
expect ( await readConfiguration ( configurationPath ) ) . to . deep . equal ( configuration ) ;
105
88
} ) ;
106
89
107
- it ( 'should register ts-node only if it is not already registered' , async ( ) => {
90
+ it ( 'should read "serverless.ts" as CJS' , async ( ) => {
91
+ await fse . ensureDir ( 'node_modules' ) ;
108
92
try {
109
- expect ( process [ Symbol . for ( 'ts-node.register.instance' ) ] ) . to . be . undefined ;
110
- process [ Symbol . for ( 'ts-node.register.instance' ) ] = 'foo' ;
111
93
configurationPath = 'serverless.ts' ;
112
94
const configuration = {
113
95
service : 'test-ts' ,
@@ -116,7 +98,22 @@ describe('test/unit/lib/configuration/read.test.js', () => {
116
98
await fsp . writeFile ( configurationPath , `module.exports = ${ JSON . stringify ( configuration ) } ` ) ;
117
99
expect ( await readConfiguration ( configurationPath ) ) . to . deep . equal ( configuration ) ;
118
100
} finally {
119
- delete process [ Symbol . for ( 'ts-node.register.instance' ) ] ;
101
+ await fse . remove ( 'node_modules' ) ;
102
+ }
103
+ } ) ;
104
+
105
+ it ( 'should read "serverless.ts" as ESM' , async ( ) => {
106
+ await fse . ensureDir ( 'node_modules' ) ;
107
+ try {
108
+ configurationPath = 'serverless.ts' ;
109
+ const configuration = {
110
+ service : 'test-ts' ,
111
+ provider : { name : 'aws' } ,
112
+ } ;
113
+ await fsp . writeFile ( configurationPath , `export default ${ JSON . stringify ( configuration ) } ` ) ;
114
+ expect ( await readConfiguration ( configurationPath ) ) . to . deep . equal ( configuration ) ;
115
+ } finally {
116
+ await fse . remove ( 'node_modules' ) ;
120
117
}
121
118
} ) ;
122
119
@@ -179,24 +176,6 @@ describe('test/unit/lib/configuration/read.test.js', () => {
179
176
) ;
180
177
} ) ;
181
178
182
- it ( 'should reject TS configuration if "ts-node" is not found' , async ( ) => {
183
- // Test against different service dir, to not fall into cached `require.resolve` value
184
- configurationPath = 'other/serverless-errored.ts' ;
185
- const configuration = {
186
- service : 'test-ts' ,
187
- provider : { name : 'aws' } ,
188
- } ;
189
- await fse . ensureFile ( configurationPath ) ;
190
- await fsp . writeFile ( configurationPath , `module.exports = ${ JSON . stringify ( configuration ) } ` ) ;
191
- await expect (
192
- proxyquire ( '../../../../lib/configuration/read' , {
193
- 'child-process-ext/spawn' : async ( ) => {
194
- throw Object . assign ( new Error ( 'Not found' ) , { code : 'ENOENT' } ) ;
195
- } ,
196
- } ) ( configurationPath )
197
- ) . to . eventually . be . rejected . and . have . property ( 'code' , 'CONFIGURATION_RESOLUTION_ERROR' ) ;
198
- } ) ;
199
-
200
179
it ( 'should reject non object configuration' , async ( ) => {
201
180
configurationPath = 'serverless.json' ;
202
181
await fsp . writeFile ( configurationPath , JSON . stringify ( [ ] ) ) ;
0 commit comments