// Cleanup.
if (needsTypeScript) {
- // rename all `.js` files to `.ts`
+ // We try to share as many files between TypeScript and JavaScript as possible.
+ // Check all the remaining `.js` files:
+ // - If the corresponding TypeScript version already exists (generated by the typescript template),
+ // remove the `.js` file.
+ // (Currently it's only `cypress/plugin/index.ts`, but we might add more in the future.)
+ // - Otherwise, rename the `.js` file to `.ts`
// rename jsconfig.json to tsconfig.json
preOrderDirectoryTraverse(
root,
() => {},
(filepath) => {
if (filepath.endsWith('.js')) {
- fs.renameSync(filepath, filepath.replace(/\.js$/, '.ts'))
+ const tsFilePath = filepath.replace(/\.js$/, '.ts')
+ if (fs.existsSync(tsFilePath)) {
+ fs.unlinkSync(filepath)
+ } else {
+ fs.renameSync(filepath, tsFilePath)
+ }
} else if (path.basename(filepath) === 'jsconfig.json') {
fs.renameSync(filepath, filepath.replace(/jsconfig\.json$/, 'tsconfig.json'))
}
--- /dev/null
+/* eslint-env node */
+/// <reference types="node" />
+/// <reference types="cypress" />
+// ***********************************************************
+// This example plugins/index.ts can be used to load plugins
+//
+// You can change the location of this file or turn off loading
+// the plugins file with the 'pluginsFile' configuration option.
+//
+// You can read more here:
+// https://on.cypress.io/plugins-guide
+// ***********************************************************
+
+// This function is called when a project is opened or re-opened (e.g. due to
+// the project's config changing)
+
+import { startDevServer } from '@cypress/vite-dev-server'
+
+export default ((on, config) => {
+ // `on` is used to hook into various events Cypress emits
+ // `config` is the resolved Cypress config
+ on('dev-server:start', (options) => {
+ return startDevServer({ options })
+ })
+ return config
+}) as Cypress.PluginConfig