File tree Expand file tree Collapse file tree 2 files changed +38
-2
lines changed
template/config/typescript/cypress/plugins Expand file tree Collapse file tree 2 files changed +38
-2
lines changed Original file line number Diff line number Diff line change @@ -282,14 +282,24 @@ async function init() {
282
282
// Cleanup.
283
283
284
284
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`
286
291
// rename jsconfig.json to tsconfig.json
287
292
preOrderDirectoryTraverse (
288
293
root ,
289
294
( ) => { } ,
290
295
( filepath ) => {
291
296
if ( filepath . endsWith ( '.js' ) ) {
292
- fs . renameSync ( filepath , filepath . replace ( / \. j s $ / , '.ts' ) )
297
+ const tsFilePath = filepath . replace ( / \. j s $ / , '.ts' )
298
+ if ( fs . existsSync ( tsFilePath ) ) {
299
+ fs . unlinkSync ( filepath )
300
+ } else {
301
+ fs . renameSync ( filepath , tsFilePath )
302
+ }
293
303
} else if ( path . basename ( filepath ) === 'jsconfig.json' ) {
294
304
fs . renameSync ( filepath , filepath . replace ( / j s c o n f i g \. j s o n $ / , 'tsconfig.json' ) )
295
305
}
Original file line number Diff line number Diff line change
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
You can’t perform that action at this time.
0 commit comments