Skip to content

Commit 2a7b0d3

Browse files
committed
fix: fix type & eslint issues in the cypress plugin file
1 parent 5fff25a commit 2a7b0d3

File tree

2 files changed

+38
-2
lines changed

2 files changed

+38
-2
lines changed

index.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,14 +282,24 @@ async function init() {
282282
// Cleanup.
283283

284284
if (needsTypeScript) {
285-
// rename all `.js` files to `.ts`
285+
// We try to share as many files between TypeScript and JavaScript as possible.
286+
// Check all the remaining `.js` files:
287+
// - If the corresponding TypeScript version already exists (generated by the typescript template),
288+
// remove the `.js` file.
289+
// (Currently it's only `cypress/plugin/index.ts`, but we might add more in the future.)
290+
// - Otherwise, rename the `.js` file to `.ts`
286291
// rename jsconfig.json to tsconfig.json
287292
preOrderDirectoryTraverse(
288293
root,
289294
() => {},
290295
(filepath) => {
291296
if (filepath.endsWith('.js')) {
292-
fs.renameSync(filepath, filepath.replace(/\.js$/, '.ts'))
297+
const tsFilePath = filepath.replace(/\.js$/, '.ts')
298+
if (fs.existsSync(tsFilePath)) {
299+
fs.unlinkSync(filepath)
300+
} else {
301+
fs.renameSync(filepath, tsFilePath)
302+
}
293303
} else if (path.basename(filepath) === 'jsconfig.json') {
294304
fs.renameSync(filepath, filepath.replace(/jsconfig\.json$/, 'tsconfig.json'))
295305
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/* eslint-env node */
2+
/// <reference types="node" />
3+
/// <reference types="cypress" />
4+
// ***********************************************************
5+
// This example plugins/index.ts can be used to load plugins
6+
//
7+
// You can change the ___location of this file or turn off loading
8+
// the plugins file with the 'pluginsFile' configuration option.
9+
//
10+
// You can read more here:
11+
// https://on.cypress.io/plugins-guide
12+
// ***********************************************************
13+
14+
// This function is called when a project is opened or re-opened (e.g. due to
15+
// the project's config changing)
16+
17+
import { startDevServer } from '@cypress/vite-dev-server'
18+
19+
export default ((on, config) => {
20+
// `on` is used to hook into various events Cypress emits
21+
// `config` is the resolved Cypress config
22+
on('dev-server:start', (options) => {
23+
return startDevServer({ options })
24+
})
25+
return config
26+
}) as Cypress.PluginConfig

0 commit comments

Comments
 (0)