With the exception of Nighwatch templates due to https://github.com/nightwatchjs/nightwatch/issues/3959
Closes #389
Largely inspired by @cexbrayat's work in that PR.
I've also made the generation of the root `tsconfig.json` programmatic
because it's becoming more and more convoluted.
Co-authored-by: Cédric Exbrayat <cexbrayat@users.noreply.github.com>
import getCommand from './utils/getCommand'
import getLanguage from './utils/getLanguage'
import renderEslint from './utils/renderEslint'
-import { FILES_TO_FILTER } from './utils/filterList'
function isValidPackageName(projectName) {
return /^(?:@[a-z0-9-*~][a-z0-9-*._~]*\/)?[a-z0-9-~][a-z0-9-._~]*$/.test(projectName)
// Render tsconfigs
render('tsconfig/base')
+ // The content of the root `tsconfig.json` is a bit complicated,
+ // So here we are programmatically generating it.
+ const rootTsConfig = {
+ // It doesn't target any specific files because they are all configured in the referenced ones.
+ files: [],
+ // All templates contain at least a `.node` and a `.app` tsconfig.
+ references: [
+ {
+ path: './tsconfig.node.json'
+ },
+ {
+ path: './tsconfig.app.json'
+ }
+ ]
+ }
if (needsCypress) {
render('tsconfig/cypress')
+ // Cypress uses `ts-node` internally, which doesn't support solution-style tsconfig.
+ // So we have to set a dummy `compilerOptions` in the root tsconfig to make it work.
+ // I use `NodeNext` here instead of `ES2015` because that's what the actual environment is.
+ // (Cypress uses the ts-node/esm loader when `type: module` is specified in package.json.)
+ // @ts-ignore
+ rootTsConfig.compilerOptions = {
+ module: 'NodeNext'
+ }
}
if (needsCypressCT) {
render('tsconfig/cypress-ct')
+ // Cypress Component Testing needs a standalone tsconfig.
+ rootTsConfig.references.push({
+ path: './tsconfig.cypress-ct.json'
+ })
}
if (needsPlaywright) {
render('tsconfig/playwright')
}
if (needsVitest) {
render('tsconfig/vitest')
+ // Vitest needs a standalone tsconfig.
+ rootTsConfig.references.push({
+ path: './tsconfig.vitest.json'
+ })
}
if (needsNightwatch) {
render('tsconfig/nightwatch')
+ // Nightwatch needs a standalone tsconfig, but in a different folder.
+ rootTsConfig.references.push({
+ path: './nightwatch/tsconfig.json'
+ })
}
if (needsNightwatchCT) {
render('tsconfig/nightwatch-ct')
}
+ fs.writeFileSync(
+ path.resolve(root, 'tsconfig.json'),
+ JSON.stringify(rootTsConfig, null, 2) + '\n',
+ 'utf-8'
+ )
}
// Render ESLint config
root,
() => {},
(filepath) => {
- if (filepath.endsWith('.js') && !FILES_TO_FILTER.includes(path.basename(filepath))) {
+ if (filepath.endsWith('.js')) {
const tsFilePath = filepath.replace(/\.js$/, '.ts')
if (fs.existsSync(tsFilePath)) {
fs.unlinkSync(filepath)
{
"private": true,
+ "type": "module",
"scripts": {
"dev": "vite",
"build": "vite build",
-const { defineConfig } = require('cypress')
+import { defineConfig } from 'cypress'
-module.exports = defineConfig({
+export default defineConfig({
e2e: {
specPattern: 'cypress/e2e/**/*.{cy,spec}.{js,jsx,ts,tsx}',
baseUrl: 'http://localhost:4173'
+++ /dev/null
-import { defineConfig } from 'cypress'
-
-export default defineConfig({
- e2e: {
- specPattern: 'cypress/e2e/**/*.{cy,spec}.{js,jsx,ts,tsx}',
- baseUrl: 'http://localhost:4173'
- },
- component: {
- specPattern: 'src/**/__tests__/*.{cy,spec}.{js,ts,jsx,tsx}',
- devServer: {
- framework: 'vue',
- bundler: 'vite'
- }
- }
-})
-const { defineConfig } = require('cypress')
+import { defineConfig } from 'cypress'
-module.exports = defineConfig({
+export default defineConfig({
e2e: {
specPattern: 'cypress/e2e/**/*.{cy,spec}.{js,jsx,ts,tsx}',
baseUrl: 'http://localhost:4173'
+++ /dev/null
-import { defineConfig } from 'cypress'
-
-export default defineConfig({
- e2e: {
- specPattern: 'cypress/e2e/**/*.{cy,spec}.{js,jsx,ts,tsx}',
- baseUrl: 'http://localhost:4173'
- }
-})
{
+ "type": "commonjs",
"scripts": {
"test:e2e": "nightwatch tests/e2e/*"
},
"devDependencies": {
"nightwatch": "^3.3.2",
- "@nightwatch/vue": "0.4.5",
+ "@nightwatch/vue": "^0.4.5",
"@vitejs/plugin-vue": "^4.5.1",
"@types/nightwatch": "^2.3.30",
"geckodriver": "^4.2.1",
-const { test, expect } = require('@playwright/test');
+import { test, expect } from '@playwright/test';
// See here how to get started:
// https://playwright.dev/docs/intro
-// @ts-check
-const { devices } = require('@playwright/test')
+import { defineConfig, devices } from '@playwright/test'
/**
* Read environment variables from file.
// require('dotenv').config();
/**
- * @see https://playwright.dev/docs/test-configuration
- * @type {import('@playwright/test').PlaywrightTestConfig}
+ * See https://playwright.dev/docs/test-configuration.
*/
-const config = {
+export default defineConfig({
testDir: './e2e',
/* Maximum time one test can run for. */
timeout: 30 * 1000,
/**
* Use the dev server by default for faster feedback loop.
* Use the preview server on CI for more realistic testing.
+ * Playwright will re-use the local server if there is already a dev-server running.
*/
command: process.env.CI ? 'vite preview --port 5173' : 'vite dev',
port: 5173,
reuseExistingServer: !process.env.CI
}
-}
-
-module.exports = config
+})
+++ /dev/null
-import type { PlaywrightTestConfig } from '@playwright/test'
-import { devices } from '@playwright/test'
-
-/**
- * Read environment variables from file.
- * https://github.com/motdotla/dotenv
- */
-// require('dotenv').config();
-
-/**
- * See https://playwright.dev/docs/test-configuration.
- */
-const config: PlaywrightTestConfig = {
- testDir: './e2e',
- /* Maximum time one test can run for. */
- timeout: 30 * 1000,
- expect: {
- /**
- * Maximum time expect() should wait for the condition to be met.
- * For example in `await expect(locator).toHaveText();`
- */
- timeout: 5000
- },
- /* Fail the build on CI if you accidentally left test.only in the source code. */
- forbidOnly: !!process.env.CI,
- /* Retry on CI only */
- retries: process.env.CI ? 2 : 0,
- /* Opt out of parallel tests on CI. */
- workers: process.env.CI ? 1 : undefined,
- /* Reporter to use. See https://playwright.dev/docs/test-reporters */
- reporter: 'html',
- /* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
- use: {
- /* Maximum time each action such as `click()` can take. Defaults to 0 (no limit). */
- actionTimeout: 0,
- /* Base URL to use in actions like `await page.goto('/')`. */
- baseURL: 'http://localhost:5173',
-
- /* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
- trace: 'on-first-retry',
-
- /* Only on CI systems run the tests headless */
- headless: !!process.env.CI
- },
-
- /* Configure projects for major browsers */
- projects: [
- {
- name: 'chromium',
- use: {
- ...devices['Desktop Chrome']
- }
- },
- {
- name: 'firefox',
- use: {
- ...devices['Desktop Firefox']
- }
- },
- {
- name: 'webkit',
- use: {
- ...devices['Desktop Safari']
- }
- }
-
- /* Test against mobile viewports. */
- // {
- // name: 'Mobile Chrome',
- // use: {
- // ...devices['Pixel 5'],
- // },
- // },
- // {
- // name: 'Mobile Safari',
- // use: {
- // ...devices['iPhone 12'],
- // },
- // },
-
- /* Test against branded browsers. */
- // {
- // name: 'Microsoft Edge',
- // use: {
- // channel: 'msedge',
- // },
- // },
- // {
- // name: 'Google Chrome',
- // use: {
- // channel: 'chrome',
- // },
- // },
- ],
-
- /* Folder for test artifacts such as screenshots, videos, traces, etc. */
- // outputDir: 'test-results/',
-
- /* Run your local dev server before starting the tests */
- webServer: {
- /**
- * Use the dev server by default for faster feedback loop.
- * Use the preview server on CI for more realistic testing.
- Playwright will re-use the local server if there is already a dev-server running.
- */
- command: process.env.CI ? 'vite preview --port 5173' : 'vite dev',
- port: 5173,
- reuseExistingServer: !process.env.CI
- }
-}
-
-export default config
+++ /dev/null
-{
- "files": [],
- "references": [
- {
- "path": "./tsconfig.node.json"
- },
- {
- "path": "./tsconfig.app.json"
- }
- ]
-}
+++ /dev/null
-{
- "files": [],
- "references": [
- {
- "path": "./tsconfig.node.json"
- },
- {
- "path": "./tsconfig.app.json"
- },
- {
- "path": "./tsconfig.cypress-ct.json"
- }
- ]
-}
+++ /dev/null
-{
- "files": [],
- "references": [
- {
- "path": "./tsconfig.node.json"
- },
- {
- "path": "./tsconfig.app.json"
- },
- {
- "path": "./nightwatch/tsconfig.json"
- }
- ]
-}
+++ /dev/null
-{
- "files": [],
- "references": [
- {
- "path": "./tsconfig.node.json"
- },
- {
- "path": "./tsconfig.app.json"
- },
- {
- "path": "./tsconfig.vitest.json"
- },
- {
- "path": "./nightwatch/tsconfig.json"
- }
- ]
-}
+++ /dev/null
-{
- "files": [],
- "references": [
- {
- "path": "./tsconfig.node.json"
- },
- {
- "path": "./tsconfig.app.json"
- },
- {
- "path": "./tsconfig.vitest.json"
- }
- ]
-}
+++ /dev/null
-export const FILES_TO_FILTER = ['nightwatch.e2e.conf.js', 'nightwatch.component.conf.js']