| "use strict"; |
| Object.defineProperty(exports, "__esModule", { |
| value: true |
| }); |
| 0 && (module.exports = { |
| SUPPORTED_TEST_RUNNERS_LIST: null, |
| nextTest: null |
| }); |
| function _export(target, all) { |
| for(var name in all)Object.defineProperty(target, name, { |
| enumerable: true, |
| get: all[name] |
| }); |
| } |
| _export(exports, { |
| SUPPORTED_TEST_RUNNERS_LIST: function() { |
| return SUPPORTED_TEST_RUNNERS_LIST; |
| }, |
| nextTest: function() { |
| return nextTest; |
| } |
| }); |
| const _fs = require("fs"); |
| const _getprojectdir = require("../lib/get-project-dir"); |
| const _utils = require("../server/lib/utils"); |
| const _config = _interop_require_default(require("../server/config")); |
| const _constants = require("../shared/lib/constants"); |
| const _hasnecessarydependencies = require("../lib/has-necessary-dependencies"); |
| const _installdependencies = require("../lib/install-dependencies"); |
| const _findup = _interop_require_default(require("next/dist/compiled/find-up")); |
| const _findpagesdir = require("../lib/find-pages-dir"); |
| const _verifytypescriptsetup = require("../lib/verify-typescript-setup"); |
| const _path = _interop_require_default(require("path")); |
| const _crossspawn = _interop_require_default(require("next/dist/compiled/cross-spawn")); |
| function _interop_require_default(obj) { |
| return obj && obj.__esModule ? obj : { |
| default: obj |
| }; |
| } |
| const SUPPORTED_TEST_RUNNERS_LIST = [ |
| 'playwright' |
| ]; |
| const requiredPackagesByTestRunner = { |
| playwright: [ |
| { |
| file: 'playwright', |
| pkg: '@playwright/test', |
| exportsRestrict: false |
| } |
| ] |
| }; |
| async function nextTest(directory, testRunnerArgs = [], options = {}) { |
| |
| |
| |
| |
| let baseDir, nextConfig; |
| try { |
| |
| baseDir = (0, _getprojectdir.getProjectDir)(directory, false); |
| } catch (err) { |
| |
| |
| testRunnerArgs.unshift(directory); |
| |
| baseDir = (0, _getprojectdir.getProjectDir)(); |
| } |
| try { |
| |
| |
| nextConfig = await (0, _config.default)(_constants.PHASE_PRODUCTION_BUILD, baseDir); |
| } catch (err) { |
| |
| |
| testRunnerArgs.unshift(directory); |
| |
| baseDir = (0, _getprojectdir.getProjectDir)(); |
| nextConfig = await (0, _config.default)(_constants.PHASE_PRODUCTION_BUILD, baseDir) |
| ; |
| } |
| |
| const configuredTestRunner = (options == null ? void 0 : options.testRunner) ?? |
| nextConfig.experimental.defaultTestRunner ?? |
| 'playwright'; |
| if (!nextConfig.experimental.testProxy) { |
| return (0, _utils.printAndExit)(`\`next experimental-test\` requires the \`experimental.testProxy: true\` configuration option.`); |
| } |
| |
| switch(configuredTestRunner){ |
| case 'playwright': |
| return runPlaywright(baseDir, nextConfig, testRunnerArgs); |
| default: |
| return (0, _utils.printAndExit)(`Test runner ${configuredTestRunner} is not supported.`); |
| } |
| } |
| async function checkRequiredDeps(baseDir, testRunner) { |
| const deps = await (0, _hasnecessarydependencies.hasNecessaryDependencies)(baseDir, requiredPackagesByTestRunner[testRunner]); |
| if (deps.missing.length > 0) { |
| await (0, _installdependencies.installDependencies)(baseDir, deps.missing, true); |
| const playwright = (0, _crossspawn.default)(_path.default.join(baseDir, 'node_modules', '.bin', 'playwright'), [ |
| 'install' |
| ], { |
| cwd: baseDir, |
| shell: false, |
| stdio: 'inherit', |
| env: { |
| ...process.env |
| } |
| }); |
| return new Promise((resolve, reject)=>{ |
| playwright.on('close', (c)=>resolve(c)); |
| playwright.on('error', (err)=>reject(err)); |
| }); |
| } |
| } |
| async function runPlaywright(baseDir, nextConfig, testRunnerArgs) { |
| await checkRequiredDeps(baseDir, 'playwright'); |
| const playwrightConfigFile = await (0, _findup.default)([ |
| 'playwright.config.js', |
| 'playwright.config.ts' |
| ], { |
| cwd: baseDir |
| }); |
| if (!playwrightConfigFile) { |
| const { pagesDir, appDir } = (0, _findpagesdir.findPagesDir)(baseDir); |
| const { version: typeScriptVersion } = await (0, _verifytypescriptsetup.verifyTypeScriptSetup)({ |
| dir: baseDir, |
| distDir: nextConfig.distDir, |
| intentDirs: [ |
| pagesDir, |
| appDir |
| ].filter(Boolean), |
| typeCheckPreflight: false, |
| tsconfigPath: nextConfig.typescript.tsconfigPath, |
| disableStaticImages: nextConfig.images.disableStaticImages, |
| hasAppDir: !!appDir, |
| hasPagesDir: !!pagesDir |
| }); |
| const isUsingTypeScript = !!typeScriptVersion; |
| const playwrightConfigFilename = isUsingTypeScript ? 'playwright.config.ts' : 'playwright.config.js'; |
| (0, _fs.writeFileSync)(_path.default.join(baseDir, playwrightConfigFilename), defaultPlaywrightConfig(isUsingTypeScript)); |
| return (0, _utils.printAndExit)(`Successfully generated ${playwrightConfigFilename}. Create your first test and then run \`next experimental-test\`.`, 0); |
| } else { |
| const playwright = (0, _crossspawn.default)(_path.default.join(baseDir, 'node_modules', '.bin', 'playwright'), [ |
| 'test', |
| ...testRunnerArgs |
| ], { |
| cwd: baseDir, |
| shell: false, |
| stdio: 'inherit', |
| env: { |
| ...process.env |
| } |
| }); |
| return new Promise((resolve, reject)=>{ |
| playwright.on('close', (c)=>resolve(c)); |
| playwright.on('error', (err)=>reject(err)); |
| }); |
| } |
| } |
| function defaultPlaywrightConfig(typescript) { |
| const comment = `/* |
| * Specify any additional Playwright config options here. |
| * They will be merged with Next.js' default Playwright config. |
| * You can access the default config by importing \`defaultPlaywrightConfig\` from \`'next/experimental/testmode/playwright'\`. |
| */`; |
| return typescript ? `import { defineConfig } from 'next/experimental/testmode/playwright';\n\n${comment}\nexport default defineConfig({});` : `const { defineConfig } = require('next/experimental/testmode/playwright');\n\n${comment}\nmodule.exports = defineConfig({});`; |
| } |
|
|
| |