Skip to content

Commit daeab10

Browse files
chrisbreidingsainthkhbrian-mann
authored
fix: Remove default esModuleInterop option from ts-node and preprocessor (#8143)
* make tests preprocessor agnostic * update eslintignore * put back deps needed for e2e test * remove obselete snapshot it was replaced by 1_typescript_support_spec.ts.js * switch from browserify to webpack preprocessor * cmon github * fix/update tests * bump preprocessor and update snapshots * update snapshots * bump preprocessor to gain json support * fix e2e tests with webpack-originated errors * bump preprocessor version, fix node globals * update snapshot * remove support for ? in file path * bump preprocessor version * bump preprocessor again * bump preprocessor * bump preprocessor * update snapshots * bump preprocessor version * bump preprocessor, quiet the paths plugin * add test verifying tsconfig paths work * refactor registering ts-node * separate spec/support file typescript tests from plugins file typescript tests * fix unit tests * fix: Remove esModuleInterop default from ts-node (#7808) * Remove esModuleInterop from ts-node. * Add e2e test. * Fix test. Change test name. Add comment. * Fix test snapshot name. * update snapshotting Co-authored-by: Chris Breiding <chrisbreiding@gmail.com> * clean up e2e project * bump preprocessor to 1.3.2, which removes esModuleInterop default value * improve esmoduleinterop e2e tests * change spec file * bump batteries-included preprocessor and install latest webpack preprocessor beside it * update snapshots * put back snapshot * update snapshot * update snapshot Co-authored-by: Kukhyeon Heo <sainthkh@naver.com> Co-authored-by: Brian Mann <brian.mann86@gmail.com>
1 parent 474bcdd commit daeab10

File tree

32 files changed

+129
-194
lines changed

32 files changed

+129
-194
lines changed

.eslintignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ packages/server/lib/scaffold/plugins/index.js
2626
packages/server/lib/scaffold/support/index.js
2727
packages/server/lib/scaffold/support/commands.js
2828
packages/server/test/support/fixtures/projects/e2e/cypress/integration/stdout_exit_early_failing_spec.js
29-
packages/server/test/support/fixtures/projects/e2e/cypress/integration/typescript_failing_spec.ts
29+
packages/server/test/support/fixtures/projects/e2e/cypress/integration/typescript_syntax_error_spec.ts
3030

3131
**/.projects
3232
**/*.d.ts

packages/server/__snapshots__/1_typescript_support_spec.ts.js renamed to packages/server/__snapshots__/1_typescript_spec_support_spec.ts.js

Lines changed: 12 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
exports['e2e typescript spec passes 1'] = `
1+
exports['e2e typescript in spec and support file spec passes 1'] = `
22
33
====================================================================================================
44
@@ -62,7 +62,7 @@ exports['e2e typescript spec passes 1'] = `
6262
6363
`
6464

65-
exports['e2e typescript spec fails 1'] = `
65+
exports['e2e typescript in spec and support file spec fails with syntax error 1'] = `
6666
6767
====================================================================================================
6868
@@ -71,23 +71,23 @@ exports['e2e typescript spec fails 1'] = `
7171
┌────────────────────────────────────────────────────────────────────────────────────────────────┐
7272
│ Cypress: 1.2.3 │
7373
│ Browser: FooBrowser 88 │
74-
│ Specs: 1 found (typescript_failing_spec.ts)
75-
│ Searched: cypress/integration/typescript_failing_spec.ts
74+
│ Specs: 1 found (typescript_syntax_error_spec.ts) │
75+
│ Searched: cypress/integration/typescript_syntax_error_spec.ts │
7676
└────────────────────────────────────────────────────────────────────────────────────────────────┘
7777
7878
7979
────────────────────────────────────────────────────────────────────────────────────────────────────
8080
81-
Running: typescript_failing_spec.ts (1 of 1)
81+
Running: typescript_syntax_error_spec.ts (1 of 1)
8282
8383
Oops...we found an error preparing this test file:
8484
85-
/foo/bar/.projects/e2e/cypress/integration/typescript_failing_spec.ts
85+
/foo/bar/.projects/e2e/cypress/integration/typescript_syntax_error_spec.ts
8686
8787
The error was:
8888
8989
Error: Webpack Compilation Error
90-
./cypress/integration/typescript_failing_spec.tsXX:XX
90+
./cypress/integration/typescript_syntax_error_spec.tsXX:XX
9191
Module parse failed: Unexpected token (4:19)
9292
File was processed with these loaders:
9393
* ../../../../node_modules/@cypress/webpack-batteries-included-preprocessor/node_modules/ts-loader/index.js
@@ -115,14 +115,15 @@ Fix the error in your code and re-run your tests.
115115
│ Screenshots: 0 │
116116
│ Video: true │
117117
│ Duration: X seconds │
118-
│ Spec Ran: typescript_failing_spec.ts
118+
│ Spec Ran: typescript_syntax_error_spec.ts │
119119
└────────────────────────────────────────────────────────────────────────────────────────────────┘
120120
121121
122122
(Video)
123123
124124
- Started processing: Compressing to 32 CRF
125-
- Finished processing: /XXX/XXX/XXX/cypress/videos/typescript_failing_spec.ts.mp4 (X second)
125+
- Finished processing: /XXX/XXX/XXX/cypress/videos/typescript_syntax_error_spec.ts (X second)
126+
.mp4
126127
127128
128129
====================================================================================================
@@ -132,14 +133,14 @@ Fix the error in your code and re-run your tests.
132133
133134
Spec Tests Passing Failing Pending Skipped
134135
┌────────────────────────────────────────────────────────────────────────────────────────────────┐
135-
│ ✖ typescript_failing_spec.ts XX:XX - - 1 - - │
136+
│ ✖ typescript_syntax_error_spec.ts XX:XX - - 1 - - │
136137
└────────────────────────────────────────────────────────────────────────────────────────────────┘
137138
✖ 1 of 1 failed (100%) XX:XX - - 1 - -
138139
139140
140141
`
141142

142-
exports['e2e typescript project passes 1'] = `
143+
exports['e2e typescript in spec and support file project passes 1'] = `
143144
144145
====================================================================================================
145146
@@ -227,20 +228,3 @@ exports['e2e typescript project passes 1'] = `
227228
228229
229230
`
230-
231-
exports['typescript with tsconfig run'] = `
232-
(Run Finished)
233-
234-
235-
Spec Tests Passing Failing Pending Skipped
236-
┌────────────────────────────────────────────────────────────────────────────────────────────────┐
237-
│ ✔ app_spec.ts XX:XX 1 1 - - - │
238-
├────────────────────────────────────────────────────────────────────────────────────────────────┤
239-
│ ✔ js-spec.js XX:XX 2 2 - - - │
240-
├────────────────────────────────────────────────────────────────────────────────────────────────┤
241-
│ ✔ math.ts XX:XX - - - - - │
242-
└────────────────────────────────────────────────────────────────────────────────────────────────┘
243-
✔ All specs passed! XX:XX 3 3 - - -
244-
245-
246-
`

packages/server/lib/plugins/child/run_plugins.js

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,13 @@
44
const _ = require('lodash')
55
const debug = require('debug')('cypress:server:plugins:child')
66
const Promise = require('bluebird')
7-
const tsnode = require('ts-node')
8-
const resolve = require('resolve')
97

108
const errors = require('../../errors')
119
const preprocessor = require('./preprocessor')
1210
const task = require('./task')
1311
const util = require('../util')
1412
const validateEvent = require('./validate_event')
15-
const tsNodeOptions = require('../../util/ts-node-options')
13+
const { registerTsNode } = require('../../util/ts-node')
1614

1715
const ARRAY_METHODS = ['concat', 'push', 'unshift', 'slice', 'pop', 'shift', 'slice', 'splice', 'filter', 'map', 'forEach', 'reduce', 'reverse', 'splice', 'includes']
1816

@@ -183,21 +181,7 @@ module.exports = (ipc, pluginsFile, projectRoot) => {
183181
})
184182

185183
if (!tsRegistered) {
186-
try {
187-
const tsPath = resolve.sync('typescript', {
188-
basedir: projectRoot,
189-
})
190-
191-
const tsOptions = tsNodeOptions.getTsNodeOptions(tsPath)
192-
193-
debug('typescript path: %s', tsPath)
194-
debug('registering plugins TS with options %o', tsOptions)
195-
196-
tsnode.register(tsOptions)
197-
} catch (e) {
198-
debug(`typescript doesn't exist. ts-node setup failed.`)
199-
debug('error message: %s', e.message)
200-
}
184+
registerTsNode(projectRoot)
201185

202186
// ensure typescript is only registered once
203187
tsRegistered = true

packages/server/lib/project.js

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ const Promise = require('bluebird')
66
const commitInfo = require('@cypress/commit-info')
77
const la = require('lazy-ass')
88
const check = require('check-more-types')
9-
const tsnode = require('ts-node')
10-
const resolve = require('resolve')
119
const scaffoldDebug = require('debug')('cypress:server:scaffold')
1210
const debug = require('debug')('cypress:server:project')
1311
const cwd = require('./cwd')
@@ -31,7 +29,7 @@ const keys = require('./util/keys')
3129
const settings = require('./util/settings')
3230
const specsUtil = require('./util/specs')
3331
const { escapeFilenameInUrl } = require('./util/escape_filename')
34-
const tsNodeOptions = require('./util/ts-node-options')
32+
const { registerTsNode } = require('./util/ts-node')
3533

3634
const localCwd = cwd()
3735

@@ -103,21 +101,7 @@ class Project extends EE {
103101
return scaffold.plugins(path.dirname(cfg.pluginsFile), cfg)
104102
}
105103
}).then((cfg) => {
106-
try {
107-
const tsPath = resolve.sync('typescript', {
108-
basedir: this.projectRoot,
109-
})
110-
111-
const tsOptions = tsNodeOptions.getTsNodeOptions(tsPath)
112-
113-
debug('typescript path: %s', tsPath)
114-
debug('registering project TS with options %o', tsOptions)
115-
116-
tsnode.register(tsOptions)
117-
} catch (e) {
118-
debug(`typescript doesn't exist. ts-node setup failed.`)
119-
debug('error message %s', e.message)
120-
}
104+
registerTsNode(this.projectRoot)
121105

122106
return cfg
123107
}).then((cfg) => {

packages/server/lib/util/ts-node-options.js

Lines changed: 0 additions & 29 deletions
This file was deleted.
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
const debug = require('debug')('cypress:server:ts-node')
2+
const tsnode = require('ts-node')
3+
const resolve = require('resolve')
4+
5+
const getTsNodeOptions = (tsPath) => {
6+
return {
7+
compiler: tsPath, // use the user's installed typescript
8+
compilerOptions: {
9+
module: 'CommonJS',
10+
},
11+
transpileOnly: true, // transpile only (no type-check) for speed
12+
}
13+
}
14+
15+
const registerTsNode = (projectRoot) => {
16+
try {
17+
const tsPath = resolve.sync('typescript', {
18+
basedir: projectRoot,
19+
})
20+
const tsOptions = getTsNodeOptions(tsPath)
21+
22+
debug('typescript path: %s', tsPath)
23+
debug('registering project TS with options %o', tsOptions)
24+
25+
tsnode.register(tsOptions)
26+
} catch (err) {
27+
debug(`typescript doesn't exist. ts-node setup failed.`)
28+
debug('error message: %s', err.message)
29+
}
30+
}
31+
32+
module.exports = {
33+
registerTsNode,
34+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import e2e from '../support/helpers/e2e'
2+
import Fixtures from '../support/helpers/fixtures'
3+
4+
describe('e2e typescript in plugins file', function () {
5+
e2e.setup()
6+
7+
it('handles tsconfig with module other than commonjs', function () {
8+
return e2e.exec(this, {
9+
project: Fixtures.projectPath('ts-proj-with-module-esnext'),
10+
})
11+
})
12+
13+
// https://github.com/cypress-io/cypress/issues/7575
14+
it('defaults to esModuleInterop: false', function () {
15+
return e2e.exec(this, {
16+
project: Fixtures.projectPath('ts-proj'),
17+
})
18+
})
19+
20+
// https://github.com/cypress-io/cypress/issues/7575
21+
it('allows esModuleInterop to be overridden with true via tsconfig.json', function () {
22+
return e2e.exec(this, {
23+
project: Fixtures.projectPath('ts-proj-esmoduleinterop-true'),
24+
})
25+
})
26+
})
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
import snapshot from 'snap-shot-it'
2-
31
import e2e from '../support/helpers/e2e'
42
import Fixtures from '../support/helpers/fixtures'
53

6-
describe('e2e typescript', function () {
4+
describe('e2e typescript in spec and support file', function () {
75
e2e.setup()
86

97
it('spec passes', function () {
@@ -13,9 +11,9 @@ describe('e2e typescript', function () {
1311
})
1412
})
1513

16-
it('spec fails', function () {
14+
it('spec fails with syntax error', function () {
1715
return e2e.exec(this, {
18-
spec: 'typescript_failing_spec.ts',
16+
spec: 'typescript_syntax_error_spec.ts',
1917
snapshot: true,
2018
expectedExitCode: 1,
2119
onStdout: e2e.normalizeWebpackErrors,
@@ -36,19 +34,4 @@ describe('e2e typescript', function () {
3634
project: Fixtures.projectPath('ts-proj-with-paths'),
3735
})
3836
})
39-
40-
it('handles tsconfig with module other than commonjs', function () {
41-
const projPath = Fixtures.projectPath('ts-proj-with-own-tsconfig')
42-
43-
return e2e.exec(this, {
44-
project: projPath,
45-
config: {
46-
video: false,
47-
},
48-
}).then((result) => {
49-
const runSummary = e2e.leaveRunFinishedTable(e2e.normalizeStdout(result.stdout))
50-
51-
snapshot('typescript with tsconfig run', runSummary)
52-
})
53-
})
5437
})
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"supportFile": false
3+
}

0 commit comments

Comments
 (0)