Skip to content

Commit a2d2f46

Browse files
authored
chore: convert @packages/icons to a compiled package and convert tests to vitest (#32649)
* chore: convert tests to vitest * chore: make icons builds from source and remove ts-node entry point to make ESM compatible * make sure the icons tests actually run in CI * correctly configure ES Module for packages/icons * chore: update ESM migration
1 parent c3828e5 commit a2d2f46

17 files changed

+112
-42
lines changed

guides/esm-migration.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,8 @@ When migrating some of these projects away from the `ts-node` entry [see `@packa
4646
- [ ] packages/example
4747
- [ ] packages/extension
4848
- [ ] packages/frontend-shared **PARTIAL** - entry point is JS
49-
- [ ] packages/https-proxy - higher priority
5049
- [x] packages/electron ✅ **COMPLETED**
51-
- [ ] packages/https-proxy **PARTIAL** - entry point is JS
50+
- [ ] packages/https-proxy - higher priority
5251
- [x] packages/icons ✅ **COMPLETED**
5352
- [x] packages/launcher ✅ **COMPLETED**
5453
- [x] packages/launchpad ✅ **COMPLETED**
@@ -98,8 +97,7 @@ When migrating some of these projects away from the `ts-node` entry [see `@packa
9897
- [ ] packages/extension
9998
- [ ] packages/https-proxy
10099
- [x] packages/electron ✅ **COMPLETED**
101-
- [ ] packages/https-proxy
102-
- [ ] packages/icons
100+
- [x] packages/icons ✅ **COMPLETED**
103101
- [ ] packages/launcher
104102
- [ ] packages/net-stubbing
105103
- [x] packages/network ✅ **COMPLETED**

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
"stop-only": "npx stop-only --skip .cy,.publish,.projects,node_modules,dist,dist-test,fixtures,lib,bower_components,src,__snapshots__,patches --exclude cypress-tests.ts,*only.cy.js",
5959
"stop-only-all": "yarn stop-only --folder packages",
6060
"pretest": "yarn ensure-deps",
61-
"test": "yarn lerna exec yarn test --scope=cypress --scope=@packages/{config,data-context,driver,electron,errors,extension,https-proxy,launcher,net-stubbing,network,packherd-require,proxy,rewriter,scaffold-config,socket,v8-snapshot-require,telemetry,stderr-filtering,types} --scope=@tooling/{electron-mksnapshot,v8-snapshot}",
61+
"test": "yarn lerna exec yarn test --scope=cypress --scope=@packages/{config,data-context,driver,electron,errors,extension,https-proxy,icons,launcher,net-stubbing,network,packherd-require,proxy,rewriter,scaffold-config,socket,v8-snapshot-require,telemetry,stderr-filtering,types} --scope=@tooling/{electron-mksnapshot,v8-snapshot}",
6262
"test-debug": "lerna exec yarn test-debug --ignore=@packages/{driver,root,static,web-config}",
6363
"test-integration": "lerna exec yarn test-integration --ignore=@packages/{driver,root,static,web-config}",
6464
"test-mocha": "mocha --reporter spec scripts/spec.js",

packages/icons/.eslintignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
**/dist
2+
index.js
3+
index.mjs
24
**/*.d.ts
5+
**/*.d.mts
36
**/package-lock.json
47
**/tsconfig.json
58
**/cypress/fixtures

packages/icons/.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
**/dist
2+
index.js
3+
index.mjs
4+
index.d.ts
5+
index.d.mts

packages/icons/index.d.ts

Lines changed: 0 additions & 1 deletion
This file was deleted.

packages/icons/index.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

packages/icons/index.mts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import path from 'path'
2+
3+
const dist = [import.meta.dirname, 'dist']
4+
5+
function distPath (...args: string[]) {
6+
return path.join.apply(path, dist.concat([...args]))
7+
}
8+
9+
export const getPathToFavicon = (filename: string) => {
10+
return distPath('favicon', filename)
11+
}
12+
13+
export const getPathToIcon = (filename: string) => {
14+
return distPath('icons', filename)
15+
}
16+
17+
export const getPathToLogo = (filename: string) => {
18+
return distPath('logo', filename)
19+
}

packages/icons/src/icons.ts renamed to packages/icons/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import path from 'path'
22

3-
const dist = [__dirname, '..', 'dist']
3+
const dist = [__dirname, 'dist']
44

55
function distPath (...args: string[]) {
66
return path.join.apply(path, dist.concat([...args]))

packages/icons/package.json

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,32 @@
55
"private": true,
66
"main": "index.js",
77
"scripts": {
8-
"build": "ts-node ./scripts/build.ts && ts-node ./scripts/ico.ts",
9-
"check-ts": "tsc --noEmit && yarn -s tslint",
8+
"build": "yarn build-assets && yarn build:cjs && yarn build:esm",
9+
"build-assets": "tsx ./scripts/build.ts && tsx ./scripts/ico.ts",
10+
"build-prod": "yarn build",
11+
"build:cjs": "tsc -p tsconfig.cjs.json",
12+
"build:esm": "tsc -p tsconfig.esm.json",
13+
"check-ts": "tsc -p tsconfig.cjs.json --noEmit && yarn -s tslint -p tsconfig.cjs.json",
1014
"lint": "eslint --ext .js,.jsx,.ts,.tsx,.json, .",
1115
"test": "yarn test-unit",
12-
"test-unit": "NODE_ENV=test mocha -r @packages/ts/register test/*.ts",
16+
"test-unit": "vitest run",
1317
"tslint": "tslint --config ../ts/tslint.json --project ."
1418
},
1519
"devDependencies": {
1620
"@types/mocha": "^8.0.3",
1721
"@types/to-ico": "^1.1.1",
18-
"chai": "^4.2.0",
1922
"fs-extra": "9.1.0",
20-
"mocha": "^8.1.3",
21-
"to-ico": "^1.1.5"
23+
"to-ico": "^1.1.5",
24+
"tsx": "^4.20.5",
25+
"vitest": "^3.2.4"
2226
},
2327
"files": [
2428
"dist",
2529
"index.js",
2630
"index.d.ts"
2731
],
32+
"types": "index.d.ts",
2833
"license": "MIT",
34+
"module": "index.mjs",
2935
"nx": {}
3036
}

packages/icons/test/icons.spec.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { describe, it, expect } from 'vitest'
2+
import * as iconsESM from '../index.mjs'
3+
import * as iconsCjs from '../index.js'
4+
5+
const cwd = process.cwd()
6+
7+
describe('Cypress Icons', function () {
8+
it('returns path to favicon', function () {
9+
expect(iconsESM.getPathToFavicon('favicon-red.ico')).toEqual(`${cwd }/dist/favicon/favicon-red.ico`)
10+
expect(iconsCjs.getPathToFavicon('favicon-red.ico')).toEqual(`${cwd }/dist/favicon/favicon-red.ico`)
11+
})
12+
13+
it('returns path to icon', function () {
14+
expect(iconsESM.getPathToIcon('cypress.icns')).toEqual(`${cwd }/dist/icons/cypress.icns`)
15+
expect(iconsCjs.getPathToIcon('cypress.icns')).toEqual(`${cwd }/dist/icons/cypress.icns`)
16+
})
17+
18+
it('returns path to logo', function () {
19+
expect(iconsESM.getPathToLogo('cypress-bw.png')).toEqual(`${cwd }/dist/logo/cypress-bw.png`)
20+
expect(iconsCjs.getPathToLogo('cypress-bw.png')).toEqual(`${cwd }/dist/logo/cypress-bw.png`)
21+
})
22+
})

0 commit comments

Comments
 (0)