Skip to content

Commit

Permalink
Merge branch '10.0-release' into tbiethman/UNIFY-1221-spec-watcher
Browse files Browse the repository at this point in the history
  • Loading branch information
tgriesser committed Apr 11, 2022
2 parents b6d8983 + 2fba9f0 commit f28308e
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 48 deletions.
2 changes: 1 addition & 1 deletion circle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ windowsWorkflowFilters: &windows-workflow-filters
or:
- equal: [ develop, << pipeline.git.branch >> ]
- equal: [ '10.0-release', << pipeline.git.branch >> ]
- equal: [ lmiller1990/merge-develop-2022-04-08, << pipeline.git.branch >> ]
- equal: [ 'lmiller1990/windows-ci-fails', << pipeline.git.branch >> ]
- matches:
pattern: "-release$"
value: << pipeline.git.branch >>
Expand Down
2 changes: 1 addition & 1 deletion packages/config/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
if (process.env.CYPRESS_INTERNAL_ENV !== 'production') {
require('@packages/ts/register')
require('@packages/ts/registerDir')(__dirname)
}

module.exports = require('./src')
4 changes: 3 additions & 1 deletion packages/data-context/src/actions/MigrationActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,12 @@ export async function processConfigViaLegacyPlugins (projectRoot: string, legacy

const cwd = path.join(projectRoot, pluginFile)

const { CYPRESS_INTERNAL_E2E_TESTING_SELF, ...env } = process.env

const childOptions: ForkOptions = {
stdio: 'inherit',
cwd: path.dirname(cwd),
env: process.env,
env,
}

const configProcessArgs = ['--projectRoot', projectRoot, '--file', cwd]
Expand Down
2 changes: 1 addition & 1 deletion packages/launchpad/cypress/e2e/migration.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ describe('Opening unmigrated project', () => {
})
})

describe('Full migration flow for each project', { retries: { openMode: 2, runMode: 2 } }, () => {
describe('Full migration flow for each project', { retries: { openMode: 2, runMode: 2 }, defaultCommandTimeout: 7000 }, () => {
it('completes journey for migration-component-testing', () => {
startMigrationFor('migration-component-testing')
// custom testFiles - cannot auto
Expand Down
4 changes: 1 addition & 3 deletions packages/launchpad/cypress/e2e/scaffold-project.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ function scaffoldAndOpenE2EProject (
cy.contains('Next').click()
cy.contains('We added the following files to your project.')
cy.contains('Continue').click()
cy.contains('Choose a Browser')
}

function scaffoldAndOpenCTProject (
Expand Down Expand Up @@ -70,7 +69,6 @@ function scaffoldAndOpenCTProject (
cy.contains('Skip').click()
cy.contains('We added the following files to your project.')
cy.contains('Continue').click()
cy.contains('Choose a Browser')
}

function assertScaffoldedFilesAreCorrect (language: 'js' | 'ts', testingType: Cypress.TestingType, ctFramework?: string) {
Expand All @@ -94,7 +92,7 @@ function assertScaffoldedFilesAreCorrect (language: 'js' | 'ts', testingType: Cy
})
}

describe('scaffolding new projects', () => {
describe('scaffolding new projects', { defaultCommandTimeout: 7000 }, () => {
it('scaffolds E2E for a JS project', () => {
scaffoldAndOpenE2EProject('pristine', 'js')
assertScaffoldedFilesAreCorrect('js', 'e2e')
Expand Down
14 changes: 8 additions & 6 deletions packages/launchpad/cypress/tasks/snapshotsScaffold.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ async function snapshotScaffoldedFiles (expectedScaffoldDir: string, filesToDiff
function compareScaffoldedFiles (filesToDiff: FileToDiff[]): SnapshotScaffoldTestResult {
for (const { actual, expected } of filesToDiff) {
try {
const read = (f: string) => fs.readFileSync(f, 'utf-8')
const actualContent = read(actual).trim()
const expectedContent = read(expected).trim()
const read = (f: string) => fs.readFileSync(f, 'utf-8').trim().replaceAll('\r\n', '\n')
const actualContent = read(actual)
const expectedContent = read(expected)
const diff = disparity.unifiedNoColor(actualContent, expectedContent, {})

if (diff !== '') {
Expand Down Expand Up @@ -116,13 +116,15 @@ export async function snapshotCypressDirectory ({ currentProject, language, test
}, [])

const actualRelativeFiles = files.map((file) => {
return file.replace(cyTmpDir, '').slice(projectName.length + 2)
const cyTmpDirPosix = joinPosix(cyTmpDir)

return file.slice(cyTmpDirPosix.length + projectName.length + 2)
})

const filesToDiff = actualRelativeFiles.map<FileToDiff>((file) => {
return {
actual: path.join(currentProject, file),
expected: path.join(expectedScaffoldDir, file),
actual: joinPosix(path.join(currentProject, file)),
expected: joinPosix(path.join(expectedScaffoldDir, file)),
}
})

Expand Down
3 changes: 2 additions & 1 deletion packages/ts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"rimraf": "3.0.2"
},
"files": [
"register.js"
"register.js",
"registerDir.js"
]
}
37 changes: 3 additions & 34 deletions packages/ts/register.js
Original file line number Diff line number Diff line change
@@ -1,34 +1,3 @@
// @ts-check
const log = require('debug')('cypress:ts')
const path = require('path')

// in development we should have TypeScript hook installed
// in production or staging we are likely to be running
// built Electron app without ts-node hook. Assume the
// build has been done correctly

try {
// Prevent double-compiling if we're testing the app and already have ts-node hook installed
// TODO(tim): e2e testing does not like this, I guess b/c it's currently using the tsconfig
// for the app project?
if (!process.env.CYPRESS_INTERNAL_E2E_TESTING_SELF) {
const tsNode = require('ts-node')
// register TypeScript Node require hook
// https://github.com/TypeStrong/ts-node#programmatic-usage
const project = require('path').join(__dirname, 'tsconfig.json')

process.env.TS_CACHED_TRANSPILE_CACHE = path.join(__dirname, 'node_modules', '.ts-cache')

tsNode.register({
compiler: 'typescript-cached-transpile',
project,
transpileOnly: true,
preferTsExts: true, // Helps when the files are compiled locally, resolves the TS file
})
}

// do we need to prevent any other TypeScript hooks?
} catch (e) {
// continue running without TypeScript require hook
log('Running without ts-node hook in environment "%s"', process.env.CYPRESS_INTERNAL_ENV)
}
// This file can be used as a shortcut to invoke `registerDir` without a scope.
// This is useful in Mocha tests with the `-r` option (`-r @packages/ts/register`)
require('./registerDir')()
40 changes: 40 additions & 0 deletions packages/ts/registerDir.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// @ts-check
const debug = require('debug')('cypress:ts')
const path = require('path')

// in development we should have TypeScript hook installed
// in production or staging we are likely to be running
// built Electron app without ts-node hook. Assume the
// build has been done correctly
module.exports = function (scopeDir) {
try {
// Prevent double-compiling if we're testing the app and already have ts-node hook installed
// TODO(tim): e2e testing does not like this, I guess b/c it's currently using the tsconfig
// for the app project?
if (!process.env.CYPRESS_INTERNAL_E2E_TESTING_SELF) {
debug('registering ts-node on directory', scopeDir)
const tsNode = require('ts-node')
// register TypeScript Node require hook
// https://github.com/TypeStrong/ts-node#programmatic-usage
const project = require('path').join(__dirname, 'tsconfig.json')

process.env.TS_CACHED_TRANSPILE_CACHE = path.join(__dirname, 'node_modules', '.ts-cache')

tsNode.register({
compiler: 'typescript-cached-transpile',
project,
transpileOnly: true,
preferTsExts: true, // Helps when the files are compiled locally, resolves the TS file
scope: Boolean(scopeDir),
scopeDir,
})
} else {
debug('skipping ts-node registration while testing the app')
}

// do we need to prevent any other TypeScript hooks?
} catch (e) {
// continue running without TypeScript require hook
debug('Running without ts-node hook in environment "%s"', process.env.CYPRESS_INTERNAL_ENV)
}
}

0 comments on commit f28308e

Please sign in to comment.