Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions assets/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
{
"compilerOptions": {
"allowSyntheticDefaultImports": true,
"noEmit": true,
"jsx": "react-jsx",
"target": "ESNext",
"module": "ESNext",
"moduleResolution": "bundler",
"types": ["node"],
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true,
"noEmit": true
},
"include": ["./src"],
"include": ["{{testDir}}", "playwright.config.ts"]
}
7 changes: 5 additions & 2 deletions src/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,11 @@ export class Generator {
for (const browserName of ['chromium', 'firefox', 'webkit'])
sections.set(browserName, !this.options.browser || this.options.browser.includes(browserName) ? 'show' : 'comment');

if (answers.language === 'TypeScript')
files.set('tsconfig.json', this._readAsset('tsconfig.json'));
if (answers.language === 'TypeScript' && !fs.existsSync(path.join(this.rootDir, 'tsconfig.json'))) {
files.set('tsconfig.json', executeTemplate(this._readAsset('tsconfig.json'), {
testDir: answers.testDir || '.',
}, new Map()));
}

files.set(`playwright.config.${fileExtension}`, executeTemplate(this._readAsset(`playwright.config.${fileExtension}`), {
testDir: answers.testDir || '',
Expand Down
23 changes: 23 additions & 0 deletions tests/integration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,29 @@ test('should generate be able to run TS examples successfully', { lock: 'apt-get
await exec(packageManagerToNpxCommand(packageManager), ['playwright', 'test']);
});

for (const testDir of ['tests', 'e2e']) {
test(`should generate a tsconfig.json that type-checks the generated files in ${testDir}`, async ({ run, exec, packageManager }) => {
test.skip(packageManager !== 'npm' && packageManager !== 'pnpm', 'tsc cannot resolve modules with PnP');
await run([], { installGitHubActions: false, testDir, language: 'TypeScript', installPlaywrightDependencies: false, installPlaywrightBrowsers: false });
const tsc = require.resolve('typescript/bin/tsc');
const { stdout } = await exec('node', [tsc, '-p', '.', '--listFilesOnly']);
// tsc prints absolute paths with forward slashes, resolved through symlinks (e.g. /private/var on macOS).
const files = stdout.split('\n').map(f => f.trim().replace(/\\/g, '/')).filter(f => f && !f.includes('/node_modules/'));
expect(files).toHaveLength(2);
expect(files.some(f => f.endsWith('/playwright.config.ts'))).toBeTruthy();
expect(files.some(f => f.endsWith(`/${testDir}/example.spec.ts`))).toBeTruthy();
await exec('node', [tsc, '-p', '.']);
});
}

test('should not overwrite an existing tsconfig.json', async ({ run, dir }) => {
const tsconfig = JSON.stringify({ compilerOptions: { strict: true } });
fs.writeFileSync(path.join(dir, 'tsconfig.json'), tsconfig);
await run(['--quiet'], { installGitHubActions: false, testDir: 'tests', language: 'TypeScript', installPlaywrightDependencies: false, installPlaywrightBrowsers: false });
expect(fs.readFileSync(path.join(dir, 'tsconfig.json'), 'utf8')).toBe(tsconfig);
expect(fs.existsSync(path.join(dir, 'playwright.config.ts'))).toBeTruthy();
});

test('should generate be able to run JS examples successfully', { lock: 'apt-get' }, async ({ run, dir, exec, packageManager }) => {
test.slow();
await run([], { installGitHubActions: false, testDir: 'tests', language: 'JavaScript', installPlaywrightDependencies: false, installPlaywrightBrowsers: true });
Expand Down
Loading