Skip to content

Commit

Permalink
fix: use posix path for ts-node loader (#22550)
Browse files Browse the repository at this point in the history
* fix: distribute files to machines for external contributors. (#22326)

* fix: distribute files to machines for external contributors.

* fix path

* fix

* fix glob

* fix

* fix glob pattern spec->cy.

* fix

* echo things.

* test

* use cd.

* fix component tests.

* test

* test

* fix

* refactor

* test distribut-step

fix error
fix
fix
test
TEST

* Revert "test distribut-step"

This reverts commit 15c3606.

* Revert "refactor"

This reverts commit 21a8ad9.

* reduce flake by increasing viewport height

Co-authored-by: Ryan Manuel <ryanm@cypress.io>
Co-authored-by: Lachlan Miller <lachlan.miller.1990@outlook.com>

* fix: add baseUrl to TestConfigOverrides (#22445)

Co-authored-by: Lachlan Miller <lachlan.miller.1990@outlook.com>

* handle white space when registering ts-node using --require

* update test project

* move config

Co-authored-by: Kukhyeon Heo <sainthkh@naver.com>
Co-authored-by: Ryan Manuel <ryanm@cypress.io>
Co-authored-by: Ishan Madhusanka <ahtimadhusanka@gmail.com>
  • Loading branch information
4 people committed Jun 28, 2022
1 parent 5d5574e commit c0ea9bd
Show file tree
Hide file tree
Showing 13 changed files with 40 additions and 12 deletions.
6 changes: 3 additions & 3 deletions packages/data-context/src/actions/MigrationActions.ts
Expand Up @@ -34,11 +34,11 @@ import {
} from '../sources/migration'
import { makeCoreData } from '../data'
import { LegacyPluginsIpc } from '../data/LegacyPluginsIpc'
import { hasTypeScriptInstalled } from '../util'
import { hasTypeScriptInstalled, toPosix } from '../util'

const debug = debugLib('cypress:data-context:MigrationActions')

const tsNode = require.resolve('@packages/server/lib/plugins/child/register_ts_node')
const tsNode = toPosix(require.resolve('@packages/server/lib/plugins/child/register_ts_node'))

export function getConfigWithDefaults (legacyConfig: any) {
const newConfig = _.cloneDeep(legacyConfig)
Expand Down Expand Up @@ -103,7 +103,7 @@ export async function processConfigViaLegacyPlugins (projectRoot: string, legacy
// this matches the 9.x behavior, which is what we want for
// processing legacy pluginsFile (we never supported `"type": "module") in 9.x.
if (hasTypeScriptInstalled(projectRoot)) {
const tsNodeLoader = `--require ${tsNode}`
const tsNodeLoader = `--require "${tsNode}"`

if (!childOptions.env) {
childOptions.env = {}
Expand Down
13 changes: 7 additions & 6 deletions packages/data-context/src/data/ProjectConfigIpc.ts
Expand Up @@ -7,7 +7,7 @@ import fs from 'fs-extra'
import path from 'path'
import inspector from 'inspector'
import debugLib from 'debug'
import { autoBindDebug, hasTypeScriptInstalled } from '../util'
import { autoBindDebug, hasTypeScriptInstalled, toPosix } from '../util'
import _ from 'lodash'
import { pathToFileURL } from 'url'

Expand All @@ -17,7 +17,7 @@ const debug = debugLib(`cypress:lifecycle:ProjectConfigIpc`)
const CHILD_PROCESS_FILE_PATH = require.resolve('@packages/server/lib/plugins/child/require_async_child')

const tsNodeEsm = pathToFileURL(require.resolve('ts-node/esm/transpile-only')).href
const tsNode = require.resolve('@packages/server/lib/plugins/child/register_ts_node')
const tsNode = toPosix(require.resolve('@packages/server/lib/plugins/child/register_ts_node'))

export type IpcHandler = (ipc: ProjectConfigIpc) => void

Expand Down Expand Up @@ -128,6 +128,7 @@ export class ProjectConfigIpc extends EventEmitter {
let resolved = false

this._childProcess.on('error', (err) => {
debug('unhandled error in child process %s', err)
this.handleChildProcessError(err, this, resolved, reject)
reject(err)
})
Expand All @@ -139,6 +140,7 @@ export class ProjectConfigIpc extends EventEmitter {
* but it's not.
*/
this.on('childProcess:unhandledError', (err) => {
debug('unhandled error in child process %s', err)
this.handleChildProcessError(err, this, resolved, reject)
reject(err)
})
Expand All @@ -150,6 +152,7 @@ export class ProjectConfigIpc extends EventEmitter {
})

this.once('loadConfig:error', (err) => {
debug('error loading config %s', err)
this.killChildProcess()
reject(err)
})
Expand Down Expand Up @@ -289,7 +292,7 @@ export class ProjectConfigIpc extends EventEmitter {
// We do NOT use the `--loader` flag because we have some additional
// custom logic for ts-node when used with CommonJS that needs to be evaluated
// so we need to load and evaluate the hook first using the `--require` module API.
const tsNodeLoader = `--require ${tsNode}`
const tsNodeLoader = `--require "${tsNode}"`

if (childOptions.env.NODE_OPTIONS) {
childOptions.env.NODE_OPTIONS += ` ${tsNodeLoader}`
Expand All @@ -302,9 +305,7 @@ export class ProjectConfigIpc extends EventEmitter {
// TODO: Consider using userland `esbuild` with Node's --loader API to handle ESM.
}

const proc = fork(CHILD_PROCESS_FILE_PATH, configProcessArgs, childOptions)

return proc
return fork(CHILD_PROCESS_FILE_PATH, configProcessArgs, childOptions)
}

private handleChildProcessError (err: any, ipc: ProjectConfigIpc, resolved: boolean, reject: (reason?: any) => void) {
Expand Down
4 changes: 2 additions & 2 deletions packages/launchpad/cypress/e2e/migration.cy.ts
Expand Up @@ -1546,8 +1546,8 @@ describe('Migration', { viewportWidth: 1200, retries: { openMode: 0, runMode: 2
})

describe('Migrate custom config files', () => {
it('completes journey for migration-custom-config-file-root-level', () => {
startMigrationFor('migration-custom-config-file-root-level', ['--config-file', 'customConfig.json'])
it('completes journey for migration-custom-config-file-root-level spaces', () => {
startMigrationFor('migration-custom-config-file-root-level spaces', ['--config-file', 'customConfig.json'])

// defaults, rename all the things
// can rename integration->e2e
Expand Down
7 changes: 7 additions & 0 deletions packages/launchpad/cypress/e2e/open-mode.cy.ts
Expand Up @@ -242,4 +242,11 @@ describe('Launchpad: Open Mode', () => {
cy.get('body').should('not.contain.text', 'Your project does not contain a default supportFile.')
cy.get('h1').should('contain', 'Choose a Browser')
})

it('opens project with spaces in path', () => {
cy.scaffoldProject('simple with spaces')
cy.openProject('simple with spaces', ['--e2e'])
cy.visitLaunchpad()
cy.get('h1').should('contain', 'Choose a Browser')
})
})
11 changes: 10 additions & 1 deletion scripts/run-webpack.js
Expand Up @@ -20,4 +20,13 @@ if (process.versions && semver.satisfies(process.versions.node, '>=17.0.0') && s
NODE_OPTIONS = `${NODE_OPTIONS} --openssl-legacy-provider`
}

cp.execSync(`node ${webpackCli} ${process.argv.slice(2).join(' ')}`, { stdio: 'inherit', env: { ...process.env, NODE_OPTIONS } })
function buildCommand () {
const file = process.argv.slice(2).join(' ') ?? ''
let program = `node "${webpackCli}"`

return file ? `${program } "${file}"` : program
}

const program = buildCommand()

cp.execSync(program, { stdio: 'inherit', env: { ...process.env, NODE_OPTIONS } })
8 changes: 8 additions & 0 deletions system-tests/projects/simple with spaces/cypress.config.js
@@ -0,0 +1,8 @@
module.exports = {
e2e: {
supportFile: false,
setupNodeEvents (on, config) {
// implement node event listeners here
},
},
}
3 changes: 3 additions & 0 deletions system-tests/projects/simple with spaces/package.json
@@ -0,0 +1,3 @@
{
"projectFixtureDirectory": "simple_passing"
}

5 comments on commit c0ea9bd

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on c0ea9bd Jun 28, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the linux x64 version of the Test Runner.

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/10.3.0/linux-x64/develop-c0ea9bdaa566a6f9296b6b70f0894a6c62d23ae3/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on c0ea9bd Jun 28, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the linux arm64 version of the Test Runner.

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/10.3.0/linux-arm64/develop-c0ea9bdaa566a6f9296b6b70f0894a6c62d23ae3/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on c0ea9bd Jun 28, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the darwin arm64 version of the Test Runner.

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/10.3.0/darwin-arm64/develop-c0ea9bdaa566a6f9296b6b70f0894a6c62d23ae3/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on c0ea9bd Jun 28, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the win32 x64 version of the Test Runner.

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/10.3.0/win32-x64/develop-c0ea9bdaa566a6f9296b6b70f0894a6c62d23ae3/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on c0ea9bd Jun 28, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the darwin x64 version of the Test Runner.

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/10.3.0/darwin-x64/develop-c0ea9bdaa566a6f9296b6b70f0894a6c62d23ae3/cypress.tgz

Please sign in to comment.