Skip to content

Commit 3aa2572

Browse files
committed
misc: convert @cypress/webpack-batteries-included-preprocessor tests to vitest
1 parent 18525dc commit 3aa2572

File tree

10 files changed

+269
-401
lines changed

10 files changed

+269
-401
lines changed

guides/esm-migration.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ When migrating some of these projects away from the `ts-node` entry [see `@packa
8888
- [x] npm/grep ✅ **COMPLETED**
8989
- [x] npm/puppeteer ✅ **COMPLETED**
9090
- [x] npm/vite-dev-server ✅ **COMPLETED**
91-
- [ ] npm/webpack-batteries-included-preprocessor
91+
- [x] npm/webpack-batteries-included-preprocessor**COMPLETED**
9292
- [x] npm/webpack-dev-server ✅ **COMPLETED**
9393
- [x] npm/webpack-preprocessor ✅ **COMPLETED**
9494

npm/webpack-batteries-included-preprocessor/eslint.config.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ export default [
99
{
1010
files: ['**/*.js', '**/*.ts'],
1111
languageOptions: {
12+
parserOptions: {
13+
tsconfigRootDir: __dirname,
14+
},
1215
globals: {
1316
...globals.node,
1417
},

npm/webpack-batteries-included-preprocessor/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ preprocessor.defaultOptions = {
278278
watchOptions: {},
279279
}
280280

281-
preprocessor.getFullWebpackOptions = (filePath: string, typescript: string | boolean) => {
281+
preprocessor.getFullWebpackOptions = (filePath: string, typescript?: string | boolean) => {
282282
const webpackOptions = getDefaultWebpackOptions()
283283

284284
if (typescript) {

npm/webpack-batteries-included-preprocessor/package.json

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@
33
"version": "0.0.0-development",
44
"description": "Cypress preprocessor for bundling JavaScript via webpack with dependencies included and support for various ES features, TypeScript, and CoffeeScript",
55
"private": false,
6-
"main": "index.js",
7-
"types": "index.d.ts",
6+
"main": "dist/index.js",
7+
"types": "dist/index.d.ts",
88
"scripts": {
99
"build": "tsc || echo 'built, with errors'",
1010
"check-ts": "tsc --noEmit",
1111
"lint": "eslint",
12-
"test": "yarn build && mocha test/**/*.spec.* --timeout 4000"
12+
"test": "vitest run",
13+
"test-debug": "vitest --inspect-brk --no-file-parallelism --test-timeout=0"
14+
1315
},
1416
"dependencies": {
1517
"@babel/core": "^7.28.0",
@@ -40,16 +42,12 @@
4042
"@packages/eslint-config": "0.0.0-development",
4143
"@types/mocha": "^8.0.2",
4244
"@types/webpack": "^5.28.1",
43-
"chai": "^4.2.0",
44-
"decache": "^4.6.2",
4545
"eslint": "^9.31.0",
4646
"globals": "^15.12.0",
4747
"jiti": "^2.4.2",
48-
"mocha": "^8.1.1",
49-
"mock-require": "3.0.3",
5048
"react": "^16.13.1",
51-
"sinon": "18.0.0",
52-
"typescript": "~5.4.5"
49+
"typescript": "~5.4.5",
50+
"vitest": "^3.2.4"
5351
},
5452
"peerDependencies": {
5553
"@cypress/webpack-preprocessor": "^6.0.4"

npm/webpack-batteries-included-preprocessor/test/e2e/features.spec.js renamed to npm/webpack-batteries-included-preprocessor/test/e2e/features.spec.ts

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
1-
const EventEmitter = require('events').EventEmitter
2-
const { expect } = require('chai')
3-
const fs = require('fs-extra')
4-
const path = require('path')
5-
6-
const preprocessor = require('../../index')
1+
import { describe, it, beforeEach, expect } from 'vitest'
2+
import { EventEmitter } from 'events'
3+
import fs from 'fs-extra'
4+
import path from 'path'
5+
import preprocessor from '../../dist/index'
76

87
const fixturesDir = path.join(__dirname, '..', 'fixtures')
98
const outputDir = path.join(__dirname, '..', '_test-output')
109

11-
const run = (fileName, options) => {
10+
const run = (fileName: string, options?: any) => {
1211
const file = Object.assign(new EventEmitter(), {
1312
filePath: path.join(outputDir, fileName),
1413
outputPath: path.join(outputDir, fileName.replace('.', '_output.')),
@@ -17,7 +16,7 @@ const run = (fileName, options) => {
1716
return preprocessor(options)(file)
1817
}
1918

20-
const runAndEval = async (fileName, options) => {
19+
const runAndEval = async (fileName: string, options?: any) => {
2120
const outputPath = await run(fileName, options)
2221
const contents = await fs.readFile(outputPath)
2322

@@ -64,14 +63,15 @@ describe('webpack-batteries-included-preprocessor features', () => {
6463
const outputPath = await run('es_features_spec.js')
6564
const contents = await fs.readFile(outputPath)
6665

67-
expect(contents.toString()).to.include('//# sourceMappingURL=data:application/json;charset=utf-8;base64')
66+
expect(contents.toString()).toContain('//# sourceMappingURL=data:application/json;charset=utf-8;base64')
6867
})
6968

7069
describe('with typescript option set', () => {
7170
const shouldntResolve = () => {
7271
throw new Error('Should error, should not resolve')
7372
}
7473

74+
// TODO: will need to use the module API in the future to replace this
7575
const options = { typescript: require.resolve('typescript') }
7676

7777
it('handles typescript (and tsconfig paths)', async () => {
@@ -105,22 +105,24 @@ describe('webpack-batteries-included-preprocessor features', () => {
105105
await runAndEval('tsx_spec.tsx', { ...options, ...preprocessor.defaultOptions })
106106
})
107107

108-
it('errors when processing .ts file and typescript option is not set', () => {
109-
return run('ts_spec.ts')
110-
.then(shouldntResolve)
111-
.catch((err) => {
112-
expect(err.message).to.include(`You are attempting to run a TypeScript file, but do not have TypeScript installed. Ensure you have 'typescript' installed to enable TypeScript support`)
113-
expect(err.message).to.include('ts_spec.ts')
114-
})
108+
it('errors when processing .ts file and typescript option is not set', async () => {
109+
try {
110+
await run('ts_spec.ts')
111+
shouldntResolve()
112+
} catch (err) {
113+
expect(err.message).toContain('You are attempting to run a TypeScript file, but do not have TypeScript installed. Ensure you have \'typescript\' installed to enable TypeScript support')
114+
expect(err.message).toContain('ts_spec.ts')
115+
}
115116
})
116117

117-
it('errors when processing .tsx file and typescript option is not set', () => {
118-
return run('tsx_spec.tsx')
119-
.then(shouldntResolve)
120-
.catch((err) => {
121-
expect(err.message).to.include(`You are attempting to run a TypeScript file, but do not have TypeScript installed. Ensure you have 'typescript' installed to enable TypeScript support`)
122-
expect(err.message).to.include('tsx_spec.tsx')
123-
})
118+
it('errors when processing .tsx file and typescript option is not set', async () => {
119+
try {
120+
await run('tsx_spec.tsx')
121+
shouldntResolve()
122+
} catch (err) {
123+
expect(err.message).toContain('You are attempting to run a TypeScript file, but do not have TypeScript installed. Ensure you have \'typescript\' installed to enable TypeScript support')
124+
expect(err.message).toContain('tsx_spec.tsx')
125+
}
124126
})
125127
})
126128
})

npm/webpack-batteries-included-preprocessor/test/unit/index.spec.js

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

0 commit comments

Comments
 (0)