Skip to content

Commit d048e46

Browse files
authored
chore: convert @packages/scaffold-config tests from mocha to vitest (#32568)
* chore: start vitest conversion and convertsupportFile to vitest * chore: convert frameworks spec to vitest * chore: convert detect spec to vitest * chore: convert ct-detect-third-party spec to vitest * chore: convert component index template to vitest * chore: clean up scaffold-config as tests are now converted to vitest * fix issue where projectRoot was passed inncorrectly in test
1 parent 942a71f commit d048e46

File tree

14 files changed

+177
-169
lines changed

14 files changed

+177
-169
lines changed

.circleci/src/workflows/@workflows.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1784,7 +1784,7 @@ jobs:
17841784
source ./scripts/ensure-node.sh
17851785
yarn lerna run types
17861786
- sanitize-verify-and-store-mocha-results:
1787-
expectedResultCount: 15
1787+
expectedResultCount: 14
17881788

17891789
verify-release-readiness:
17901790
<<: *defaults

.circleci/workflows.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3486,7 +3486,7 @@ jobs:
34863486
yarn lerna run types
34873487
name: Test types
34883488
- sanitize-verify-and-store-mocha-results:
3489-
expectedResultCount: 15
3489+
expectedResultCount: 14
34903490
working_directory: ~/cypress
34913491
v8-integration-tests:
34923492
environment:

guides/esm-migration.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@
102102
- [ ] packages/packherd-require
103103
- [ ] packages/proxy
104104
- [ ] packages/rewriter
105-
- [ ] packages/scaffold-config
105+
- [x] packages/scaffold-config**COMPLETED**
106106
- [ ] packages/server
107107
- [ ] packages/socket
108108
- [x] packages/stderr-filtering ✅ **COMPLETED**

packages/scaffold-config/package.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
"clean": "rimraf --glob './src/*.js' './src/**/*.js' './src/**/**/*.js' './test/**/*.js' || echo 'cleaned'",
1111
"clean-deps": "rimraf node_modules",
1212
"lint": "eslint --ext .js,.jsx,.ts,.tsx,.json, .",
13-
"test": "yarn test-unit",
14-
"test-unit": "mocha -r @packages/ts/register 'test/unit/**' --config ./test/.mocharc.js --exit --reporter mocha-multi-reporters --reporter-options configFile=../../mocha-reporter-config.json",
13+
"test": "vitest run",
14+
"test-debug": "npx vitest --inspect-brk --no-file-parallelism --test-timeout=0",
1515
"tslint": "tslint --config ../ts/tslint.json --project ."
1616
},
1717
"dependencies": {
@@ -28,8 +28,7 @@
2828
"devDependencies": {
2929
"@packages/ts": "0.0.0-development",
3030
"@packages/types": "0.0.0-development",
31-
"chai": "4.2.0",
32-
"mocha": "7.0.1"
31+
"vitest": "^3.2.4"
3332
},
3433
"files": [
3534
"src"

packages/scaffold-config/src/detect.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,15 @@ export function detectLanguage ({ projectRoot, customConfigFile, pkgJson }: Dete
171171
try {
172172
const typescriptFile = require.resolve('typescript', { paths: [projectRoot] })
173173

174+
// sometimes require.resolve returns a path that does not exist but is cached by require.resolve()
175+
const exists = fs.existsSync(typescriptFile)
176+
177+
if (!exists) {
178+
debug('Resolved typescript from %s does not exist', typescriptFile)
179+
180+
return 'js'
181+
}
182+
174183
debug('Resolved typescript from %s', typescriptFile)
175184
} catch {
176185
debug('No typescript installed - using js')

packages/scaffold-config/test/.mocharc.js

Lines changed: 0 additions & 3 deletions
This file was deleted.

packages/scaffold-config/test/unit/component-index-template.spec.ts renamed to packages/scaffold-config/test/component-index-template.spec.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { expect } from 'chai'
1+
import { describe, it, expect } from 'vitest'
22
import dedent from 'dedent'
3-
import componentIndexHtmlGenerator from '../../src/component-index-template'
4-
import { CT_FRAMEWORKS } from '../../src/frameworks'
3+
import componentIndexHtmlGenerator from '../src/component-index-template'
4+
import { CT_FRAMEWORKS } from '../src/frameworks'
55

66
describe('componentIndexHtmlGenerator', () => {
77
it('strips spaces and newlines appropriately', () => {
@@ -21,7 +21,7 @@ describe('componentIndexHtmlGenerator', () => {
2121
</body>
2222
</html>`
2323

24-
expect(generator()).to.eq(expected)
24+
expect(generator()).toEqual(expected)
2525
})
2626

2727
it('handles header modifier', () => {
@@ -42,7 +42,7 @@ describe('componentIndexHtmlGenerator', () => {
4242
</body>
4343
</html>`
4444

45-
expect(generator()).to.eq(expected)
45+
expect(generator()).toEqual(expected)
4646
})
4747

4848
it('generates correct template for Next.js', () => {
@@ -66,6 +66,6 @@ describe('componentIndexHtmlGenerator', () => {
6666
</body>
6767
</html>`
6868

69-
expect(actual).to.eq(expected)
69+
expect(actual).toEqual(expected)
7070
})
7171
})

packages/scaffold-config/test/unit/ct-detect-third-party.spec.ts renamed to packages/scaffold-config/test/ct-detect-third-party.spec.ts

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { scaffoldMigrationProject, fakeDepsInNodeModules } from './detect.spec'
1+
import { describe, it, expect, beforeEach, afterEach } from 'vitest'
2+
import { scaffoldMigrationProject, fakeDepsInNodeModules } from './scaffolding'
23
import fs from 'fs-extra'
34
import path from 'path'
4-
import { detectThirdPartyCTFrameworks, validateThirdPartyModule, isThirdPartyDefinition, isRepositoryRoot } from '../../src'
5-
import { expect } from 'chai'
5+
import { detectThirdPartyCTFrameworks, validateThirdPartyModule, isThirdPartyDefinition, isRepositoryRoot } from '../src'
66
import os from 'os'
77
import solidJs from './fixtures'
88

@@ -25,31 +25,31 @@ async function scaffoldQwikApp (thirdPartyModuleNames: Array<'cypress-ct-qwik' |
2525
}
2626

2727
describe('isThirdPartyDefinition', () => {
28-
context('global package', () => {
28+
describe('global package', () => {
2929
it('returns false for invalid prefix', () => {
3030
const res = isThirdPartyDefinition({ ...solidJs, type: 'non-cypress-ct' })
3131

32-
expect(res).to.be.false
32+
expect(res).toBe(false)
3333
})
3434

3535
it('returns true for valid prefix', () => {
3636
const res = isThirdPartyDefinition({ ...solidJs, type: 'cypress-ct-solid-js' })
3737

38-
expect(res).to.be.true
38+
expect(res).toBe(true)
3939
})
4040
})
4141

42-
context('namespaced package', () => {
42+
describe('namespaced package', () => {
4343
it('returns false for non third party with namespace', () => {
4444
const res = isThirdPartyDefinition({ ...solidJs, type: '@org/non-cypress-ct' })
4545

46-
expect(res).to.be.false
46+
expect(res).toBe(false)
4747
})
4848

4949
it('returns true for third party with namespace', () => {
5050
const res = isThirdPartyDefinition({ ...solidJs, type: '@org/cypress-ct-solid-js' })
5151

52-
expect(res).to.be.true
52+
expect(res).toBe(true)
5353
})
5454
})
5555
})
@@ -68,15 +68,15 @@ describe('isRepositoryRoot', () => {
6868
it('returns false if there is nothing in the directory', async () => {
6969
const isCurrentRepositoryRoot = await isRepositoryRoot(TEMP_DIR)
7070

71-
expect(isCurrentRepositoryRoot).to.be.false
71+
expect(isCurrentRepositoryRoot).toBe(false)
7272
})
7373

7474
it('returns true if there is a Git directory', async () => {
7575
await fs.mkdir(path.join(TEMP_DIR, '.git'))
7676

7777
const isCurrentRepositoryRoot = await isRepositoryRoot(TEMP_DIR)
7878

79-
expect(isCurrentRepositoryRoot).to.be.true
79+
expect(isCurrentRepositoryRoot).toBe(true)
8080
})
8181

8282
it('returns false if there is a package.json without workspaces field', async () => {
@@ -91,7 +91,7 @@ describe('isRepositoryRoot', () => {
9191

9292
const isCurrentRepositoryRoot = await isRepositoryRoot(TEMP_DIR)
9393

94-
expect(isCurrentRepositoryRoot).to.be.false
94+
expect(isCurrentRepositoryRoot).toBe(false)
9595
})
9696

9797
it('returns true if there is a package.json with workspaces field', async () => {
@@ -109,7 +109,7 @@ describe('isRepositoryRoot', () => {
109109

110110
const isCurrentRepositoryRoot = await isRepositoryRoot(TEMP_DIR)
111111

112-
expect(isCurrentRepositoryRoot).to.be.true
112+
expect(isCurrentRepositoryRoot).toBe(true)
113113
})
114114
})
115115

@@ -119,24 +119,24 @@ describe('detectThirdPartyCTFrameworks', () => {
119119

120120
const thirdPartyFrameworks = await detectThirdPartyCTFrameworks(projectRoot)
121121

122-
expect(thirdPartyFrameworks.frameworks[0].type).eq('cypress-ct-qwik')
122+
expect(thirdPartyFrameworks.frameworks[0].type).toEqual('cypress-ct-qwik')
123123
})
124124

125125
it('detects third party frameworks in org namespace', async () => {
126126
const projectRoot = await scaffoldQwikApp(['@org/cypress-ct-qwik'])
127127

128128
const thirdPartyFrameworks = await detectThirdPartyCTFrameworks(projectRoot)
129129

130-
expect(thirdPartyFrameworks.frameworks[0].type).eq('@org/cypress-ct-qwik')
130+
expect(thirdPartyFrameworks.frameworks[0].type).toEqual('@org/cypress-ct-qwik')
131131
})
132132

133133
it('ignores misconfigured third party frameworks', async () => {
134134
const projectRoot = await scaffoldQwikApp(['cypress-ct-qwik', 'misconfigured-cypress-ct-qwik'])
135135

136136
const thirdPartyFrameworks = await detectThirdPartyCTFrameworks(projectRoot)
137137

138-
expect(thirdPartyFrameworks.frameworks.length).eq(1)
139-
expect(thirdPartyFrameworks.frameworks[0].type).eq('cypress-ct-qwik')
138+
expect(thirdPartyFrameworks.frameworks.length).toEqual(1)
139+
expect(thirdPartyFrameworks.frameworks[0].type).toEqual('cypress-ct-qwik')
140140
})
141141

142142
it('detects third party frameworks in monorepos with hoisted dependencies', async () => {
@@ -150,19 +150,19 @@ describe('detectThirdPartyCTFrameworks', () => {
150150
// Look for third-party modules in packages/foo (where Cypress was launched from)
151151
const thirdPartyFrameworks = await detectThirdPartyCTFrameworks(projectRoot)
152152

153-
expect(thirdPartyFrameworks.frameworks[0].type).eq('cypress-ct-qwik')
153+
expect(thirdPartyFrameworks.frameworks[0].type).toEqual('cypress-ct-qwik')
154154
})
155155

156156
it('validates third party module', () => {
157-
expect(() => validateThirdPartyModule(solidJs)).to.not.throw()
157+
expect(() => validateThirdPartyModule(solidJs)).not.toThrow()
158158

159159
const gen = (m: any) => m
160160

161-
expect(() => validateThirdPartyModule(gen({ ...solidJs, type: 'misconfigured' }))).to.throw()
161+
expect(() => validateThirdPartyModule(gen({ ...solidJs, type: 'misconfigured' }))).toThrow()
162162
expect(() => validateThirdPartyModule(gen({ ...solidJs, name: 5 }))).to.throw()
163-
expect(() => validateThirdPartyModule(gen({ ...solidJs, supportedBundlers: ['random'] }))).to.throw()
164-
expect(() => validateThirdPartyModule(gen({ ...solidJs, detectors: {} }))).to.throw()
165-
expect(() => validateThirdPartyModule(gen({ ...solidJs, dependencies: {} }))).to.throw()
166-
expect(() => validateThirdPartyModule(gen({ ...solidJs, componentIndexHtml: {} }))).to.throw()
163+
expect(() => validateThirdPartyModule(gen({ ...solidJs, supportedBundlers: ['random'] }))).toThrow()
164+
expect(() => validateThirdPartyModule(gen({ ...solidJs, detectors: {} }))).toThrow()
165+
expect(() => validateThirdPartyModule(gen({ ...solidJs, dependencies: {} }))).toThrow()
166+
expect(() => validateThirdPartyModule(gen({ ...solidJs, componentIndexHtml: {} }))).toThrow()
167167
})
168168
})

0 commit comments

Comments
 (0)