-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
96 additions
and
86 deletions.
There are no files selected for viewing
1 change: 0 additions & 1 deletion
1
packages/create-playwright/assets/examples/2-element-selectors.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
|
||
import { test } from '@playwright/test'; | ||
|
||
// Element selector overview, for more information see | ||
|
1 change: 0 additions & 1 deletion
1
packages/create-playwright/assets/examples/3-assertions.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 0 additions & 1 deletion
1
packages/create-playwright/assets/examples/7-mock-network-requests.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
|
||
import { test, expect } from '@playwright/test'; | ||
|
||
test.beforeEach(async ({ context }) => { | ||
|
2 changes: 1 addition & 1 deletion
2
packages/create-playwright/assets/examples/server/assets/api/v1/users.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
{ | ||
"id": 1, | ||
"fullName": "John Doe" | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
packages/create-playwright/assets/examples/server/assets/index.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
<object data="header.html" style="width: 100%; height: 200px;"> | ||
Your browser doesn’t support the object tag. | ||
</object> | ||
</object> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,4 +35,4 @@ | |
|
||
<button>Buy</button> | ||
<button>Buy</button> | ||
<button>Buy</button> | ||
<button>Buy</button> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
/** | ||
* Copyright (c) Microsoft Corporation. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import { test as base } from '@playwright/test'; | ||
import { spawn, SpawnOptions } from 'child_process'; | ||
import path from 'path'; | ||
import fs from 'fs'; | ||
import { PromptOptions } from '../src'; | ||
|
||
type TestFixtures = { | ||
packageManager: 'npm' | 'yarn'; | ||
run: (parameters: string[], options: PromptOptions) => Promise<RunResult>, | ||
}; | ||
|
||
type RunResult = { | ||
exitCode: number, | ||
dir: string, | ||
stdout: string, | ||
exec: typeof spawnAsync | ||
}; | ||
|
||
function spawnAsync(cmd: string, args: string[], options?: SpawnOptions): Promise<{stdout: string, stderr: string, code: number, error?: Error}> { | ||
const p = spawn(cmd, args, options); | ||
|
||
return new Promise(resolve => { | ||
let stdout = ''; | ||
let stderr = ''; | ||
if (process.env.DEBUG) { | ||
p.stdout.on('data', chunk => process.stdout.write(chunk)); | ||
p.stderr.on('data', chunk => process.stderr.write(chunk)); | ||
} | ||
if (p.stdout) | ||
p.stdout.on('data', data => stdout += data); | ||
if (p.stderr) | ||
p.stderr.on('data', data => stderr += data); | ||
p.on('close', code => resolve({stdout, stderr, code})); | ||
p.on('error', error => resolve({stdout, stderr, code: 0, error})); | ||
}); | ||
} | ||
|
||
export const test = base.extend<TestFixtures>({ | ||
packageManager: 'npm', | ||
run: async ({ packageManager }, use, testInfo) => { | ||
await use(async (parameters: string[], options: PromptOptions): Promise<RunResult> => { | ||
fs.mkdirSync(testInfo.outputDir, { recursive: true }); | ||
const env = packageManager === 'yarn' ? { | ||
'npm_config_user_agent': 'yarn' | ||
} : undefined; | ||
const result = await spawnAsync('node', [path.join(__dirname, '..'), ...parameters], { | ||
shell: true, | ||
cwd: testInfo.outputDir, | ||
env: { | ||
...process.env, | ||
...env, | ||
'TEST_OPTIONS': JSON.stringify(options), | ||
} | ||
}); | ||
const execWrapper = (cmd: string, args: string[], options?: SpawnOptions): ReturnType<typeof spawnAsync> => { | ||
return spawnAsync(cmd, args, { | ||
...options, | ||
cwd: testInfo.outputDir, | ||
}); | ||
}; | ||
return { | ||
exitCode: result.code, | ||
dir: testInfo.outputDir, | ||
stdout: result.stdout, | ||
exec: execWrapper, | ||
}; | ||
}); | ||
}, | ||
}); | ||
|
||
export const expect = test.expect; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters