Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Remove default esModuleInterop option from ts-node and preproces…
…sor (#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>
- Loading branch information
1 parent
474bcdd
commit daeab10
Showing
32 changed files
with
129 additions
and
194 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
const debug = require('debug')('cypress:server:ts-node') | ||
const tsnode = require('ts-node') | ||
const resolve = require('resolve') | ||
|
||
const getTsNodeOptions = (tsPath) => { | ||
return { | ||
compiler: tsPath, // use the user's installed typescript | ||
compilerOptions: { | ||
module: 'CommonJS', | ||
}, | ||
transpileOnly: true, // transpile only (no type-check) for speed | ||
} | ||
} | ||
|
||
const registerTsNode = (projectRoot) => { | ||
try { | ||
const tsPath = resolve.sync('typescript', { | ||
basedir: projectRoot, | ||
}) | ||
const tsOptions = getTsNodeOptions(tsPath) | ||
|
||
debug('typescript path: %s', tsPath) | ||
debug('registering project TS with options %o', tsOptions) | ||
|
||
tsnode.register(tsOptions) | ||
} catch (err) { | ||
debug(`typescript doesn't exist. ts-node setup failed.`) | ||
debug('error message: %s', err.message) | ||
} | ||
} | ||
|
||
module.exports = { | ||
registerTsNode, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import e2e from '../support/helpers/e2e' | ||
import Fixtures from '../support/helpers/fixtures' | ||
|
||
describe('e2e typescript in plugins file', function () { | ||
e2e.setup() | ||
|
||
it('handles tsconfig with module other than commonjs', function () { | ||
return e2e.exec(this, { | ||
project: Fixtures.projectPath('ts-proj-with-module-esnext'), | ||
}) | ||
}) | ||
|
||
// https://github.com/cypress-io/cypress/issues/7575 | ||
it('defaults to esModuleInterop: false', function () { | ||
return e2e.exec(this, { | ||
project: Fixtures.projectPath('ts-proj'), | ||
}) | ||
}) | ||
|
||
// https://github.com/cypress-io/cypress/issues/7575 | ||
it('allows esModuleInterop to be overridden with true via tsconfig.json', function () { | ||
return e2e.exec(this, { | ||
project: Fixtures.projectPath('ts-proj-esmoduleinterop-true'), | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
3 changes: 3 additions & 0 deletions
3
packages/server/test/support/fixtures/projects/ts-proj-esmoduleinterop-true/cypress.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"supportFile": false | ||
} |
3 changes: 3 additions & 0 deletions
3
...upport/fixtures/projects/ts-proj-esmoduleinterop-true/cypress/integration/passing_spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
it('passes', () => { | ||
expect(true).to.be.true | ||
}) |
3 changes: 3 additions & 0 deletions
3
...support/fixtures/projects/ts-proj-esmoduleinterop-true/cypress/plugins/commonjs-export.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
exports.export1 = 'export1' | ||
|
||
exports.export2 = 'export2' |
12 changes: 12 additions & 0 deletions
12
...rver/test/support/fixtures/projects/ts-proj-esmoduleinterop-true/cypress/plugins/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/// <reference types="cypress" /> | ||
|
||
import commonjsExports from './commonjs-export' | ||
|
||
if (commonjsExports.export1 !== 'export1' || commonjsExports.export2 !== 'export2') { | ||
throw new Error('Imported values do not match exported values') | ||
} | ||
|
||
// Default Cypress plugin function | ||
export default (on: Cypress.PluginEvents, config: Cypress.PluginConfigOptions) => { | ||
|
||
} |
5 changes: 5 additions & 0 deletions
5
packages/server/test/support/fixtures/projects/ts-proj-esmoduleinterop-true/tsconfig.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"compilerOptions": { | ||
"esModuleInterop": true | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
packages/server/test/support/fixtures/projects/ts-proj-with-module-esnext/cypress.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"supportFolder": false | ||
} |
5 changes: 5 additions & 0 deletions
5
...ts/ts-proj-with-module-esnext/cypress/integration/uses_cy_task_in_ts_plugins_file_spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
describe('uses task that is in typescript plugins file', () => { | ||
it('calls task', () => { | ||
cy.task('hello', 'TS').should('equal', 'Hello, TS!') | ||
}) | ||
}) |
3 changes: 3 additions & 0 deletions
3
...ver/test/support/fixtures/projects/ts-proj-with-module-esnext/cypress/plugins/greeting.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export const asyncGreeting = async (greeting: string) => { | ||
return Promise.resolve(`Hello, ${greeting}!`) | ||
} |
File renamed without changes.
File renamed without changes.
1 change: 0 additions & 1 deletion
1
packages/server/test/support/fixtures/projects/ts-proj-with-own-tsconfig/cypress.json
This file was deleted.
Oops, something went wrong.
5 changes: 0 additions & 5 deletions
5
.../test/support/fixtures/projects/ts-proj-with-own-tsconfig/cypress/integration/app_spec.ts
This file was deleted.
Oops, something went wrong.
11 changes: 0 additions & 11 deletions
11
...r/test/support/fixtures/projects/ts-proj-with-own-tsconfig/cypress/integration/js-spec.js
This file was deleted.
Oops, something went wrong.
3 changes: 0 additions & 3 deletions
3
...rver/test/support/fixtures/projects/ts-proj-with-own-tsconfig/cypress/integration/math.ts
This file was deleted.
Oops, something went wrong.
3 changes: 0 additions & 3 deletions
3
...rver/test/support/fixtures/projects/ts-proj-with-own-tsconfig/cypress/plugins/greeting.ts
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.