@knapsack-pro/playwright 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +58 -0
- package/lib/knapsack-playwright.js +34 -0
- package/lib/reporters/batch.js +44 -0
- package/lib/reporters/list.js +22 -0
- package/lib/reporters/reporterV2.js +1 -0
- package/lib/reporters/utils.js +5 -0
- package/package.json +51 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
Copyright (c) 2025 Knapsack Sp. z o.o. https://knapsackpro.com
|
|
2
|
+
|
|
3
|
+
MIT License
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
# @knapsack-pro/playwright
|
|
2
|
+
|
|
3
|
+
<p align="center">
|
|
4
|
+
<a href="https://knapsackpro.com?utm_source=github&utm_medium=readme&utm_campaign=knapsack-pro-playwright&utm_content=hero_logo">
|
|
5
|
+
<img alt="Knapsack Pro" src="./.github/assets/knapsack.png" width="300" height="300" style="max-width: 100%;" />
|
|
6
|
+
</a>
|
|
7
|
+
</p>
|
|
8
|
+
|
|
9
|
+
<h3 align="center">Speed up your tests</h3>
|
|
10
|
+
<p align="center">Run your 1-hour test suite in 2 minutes with optimal parallelisation on your existing CI infrastructure</p>
|
|
11
|
+
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
<div align="center">
|
|
15
|
+
<a href="https://circleci.com/gh/KnapsackPro/knapsack-pro-js">
|
|
16
|
+
<img alt="Circle CI" src="https://circleci.com/gh/KnapsackPro/knapsack-pro-js.svg?style=svg" />
|
|
17
|
+
</a>
|
|
18
|
+
</div>
|
|
19
|
+
|
|
20
|
+
<br />
|
|
21
|
+
<br />
|
|
22
|
+
|
|
23
|
+
Knapsack Pro wraps [Playwright](https://playwright.dev/) and works with your existing CI infrastructure to parallelize tests optimally:
|
|
24
|
+
|
|
25
|
+
- Dynamically splits your tests based on up-to-date test execution data
|
|
26
|
+
- Is designed from the ground up for CI and supports all of them
|
|
27
|
+
- Tracks your CI builds to detect bottlenecks
|
|
28
|
+
- Does not have access to your source code and collects minimal test data
|
|
29
|
+
- Enables you to export historical metrics about your CI builds
|
|
30
|
+
- Replaces local dependencies like Redis with an API and runs your tests regardless of network problems
|
|
31
|
+
|
|
32
|
+
## Installation
|
|
33
|
+
|
|
34
|
+
See the [docs](https://docs.knapsackpro.com/playwright/guide/) to get started:
|
|
35
|
+
|
|
36
|
+
<div align="center">
|
|
37
|
+
<a href="https://docs.knapsackpro.com/playwright/guide/">
|
|
38
|
+
<img alt="Install button" src="./.github/assets/install-button.png" width="116" height="50" />
|
|
39
|
+
</a>
|
|
40
|
+
</div>
|
|
41
|
+
|
|
42
|
+
## Dependencies
|
|
43
|
+
|
|
44
|
+
- [@knapsack-pro/core](https://github.com/KnapsackPro/knapsack-pro-js/tree/main/packages/core)
|
|
45
|
+
|
|
46
|
+
## Contributing
|
|
47
|
+
|
|
48
|
+
Follow the steps in the [root README.md](https://github.com/KnapsackPro/knapsack-pro-js#contributing) to set up the project.
|
|
49
|
+
|
|
50
|
+
### Testing
|
|
51
|
+
|
|
52
|
+
To test `@knapsack-pro/playwright` against a real test suite we use:
|
|
53
|
+
|
|
54
|
+
- [playwright-example-test-suite](https://github.com/KnapsackPro/knapsack-pro-js/tree/main/packages/playwright-example-test-suite)
|
|
55
|
+
|
|
56
|
+
### Publishing
|
|
57
|
+
|
|
58
|
+
See [Publishing](../../#publishing) in the root README.md.
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { readFileSync, mkdirSync, rmSync } from 'fs';
|
|
3
|
+
import { execSync, spawnSync } from 'child_process';
|
|
4
|
+
import pkg from '@knapsack-pro/playwright/package.json' with { type: 'json' };
|
|
5
|
+
import { KnapsackProCore, KnapsackProLogger, } from '@knapsack-pro/core';
|
|
6
|
+
if (process.env.KNAPSACK_PRO_TEST_SUITE_TOKEN_PLAYWRIGHT) {
|
|
7
|
+
process.env.KNAPSACK_PRO_TEST_SUITE_TOKEN =
|
|
8
|
+
process.env.KNAPSACK_PRO_TEST_SUITE_TOKEN_PLAYWRIGHT;
|
|
9
|
+
}
|
|
10
|
+
async function main() {
|
|
11
|
+
const knapsackProLogger = new KnapsackProLogger();
|
|
12
|
+
knapsackProLogger.debug(`Running ${pkg.name}@${pkg.version}`);
|
|
13
|
+
mkdirSync('.knapsack-pro', { recursive: true });
|
|
14
|
+
const cliArguments = process.argv.slice(2).join(' ');
|
|
15
|
+
knapsackProLogger.debug(`cliArguments: ${cliArguments}`);
|
|
16
|
+
const command = `npx playwright test --list ${cliArguments} --reporter=@knapsack-pro/playwright/reporters/list`;
|
|
17
|
+
knapsackProLogger.debug(`Executing: ${command}`);
|
|
18
|
+
execSync(command, { stdio: 'ignore' });
|
|
19
|
+
const tests = JSON.parse(readFileSync('.knapsack-pro/list.json', 'utf8'));
|
|
20
|
+
knapsackProLogger.debug(`Tests to run: ${tests}`);
|
|
21
|
+
const knapsackPro = new KnapsackProCore(pkg.name, pkg.version, () => tests.map((testFilePath) => ({ path: testFilePath })));
|
|
22
|
+
const onSuccess = async (testFiles) => {
|
|
23
|
+
const paths = testFiles.map((testFile) => testFile.path).join(' ');
|
|
24
|
+
const command = `PWTEST_BLOB_DO_NOT_REMOVE=1 npx playwright test ${cliArguments} ${paths}`;
|
|
25
|
+
knapsackProLogger.debug(`Executing: ${command}`);
|
|
26
|
+
spawnSync(command, { shell: true, stdio: 'inherit' });
|
|
27
|
+
const batch = readFileSync('.knapsack-pro/batch.json', 'utf8');
|
|
28
|
+
rmSync('.knapsack-pro/batch.json');
|
|
29
|
+
return JSON.parse(batch);
|
|
30
|
+
};
|
|
31
|
+
const onError = () => { };
|
|
32
|
+
knapsackPro.runQueueMode(onSuccess, onError);
|
|
33
|
+
}
|
|
34
|
+
main();
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { writeFileSync, mkdirSync } from 'fs';
|
|
2
|
+
import { pathWithRootDir } from './utils.js';
|
|
3
|
+
class BatchReporter {
|
|
4
|
+
config;
|
|
5
|
+
tally;
|
|
6
|
+
constructor() {
|
|
7
|
+
this.tally = new Map();
|
|
8
|
+
}
|
|
9
|
+
version() {
|
|
10
|
+
return 'v2';
|
|
11
|
+
}
|
|
12
|
+
printsToStdio() {
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
onConfigure(config) {
|
|
16
|
+
this.config = config;
|
|
17
|
+
}
|
|
18
|
+
onTestEnd(test, result) {
|
|
19
|
+
if (result.status !== 'passed')
|
|
20
|
+
return;
|
|
21
|
+
const duration = result.duration / 1000;
|
|
22
|
+
const path = pathWithRootDir(test, this.config);
|
|
23
|
+
const current = this.tally.get(path);
|
|
24
|
+
if (current) {
|
|
25
|
+
this.tally.set(path, current + duration);
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
this.tally.set(path, duration);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
onEnd(result) {
|
|
32
|
+
const recordedTestFiles = Array.from(this.tally).map(([path, duration]) => ({
|
|
33
|
+
path,
|
|
34
|
+
time_execution: duration,
|
|
35
|
+
}));
|
|
36
|
+
const res = {
|
|
37
|
+
recordedTestFiles,
|
|
38
|
+
isTestSuiteGreen: result.status === 'passed',
|
|
39
|
+
};
|
|
40
|
+
mkdirSync('.knapsack-pro', { recursive: true });
|
|
41
|
+
writeFileSync('.knapsack-pro/batch.json', JSON.stringify(res));
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
export default BatchReporter;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { writeFileSync } from 'fs';
|
|
2
|
+
import { pathWithRootDir } from './utils.js';
|
|
3
|
+
class ListReporter {
|
|
4
|
+
config;
|
|
5
|
+
version() {
|
|
6
|
+
return 'v2';
|
|
7
|
+
}
|
|
8
|
+
printsToStdio() {
|
|
9
|
+
return true;
|
|
10
|
+
}
|
|
11
|
+
onConfigure(config) {
|
|
12
|
+
this.config = config;
|
|
13
|
+
}
|
|
14
|
+
onBegin(suite) {
|
|
15
|
+
const paths = new Set();
|
|
16
|
+
suite
|
|
17
|
+
.allTests()
|
|
18
|
+
.forEach((test) => paths.add(pathWithRootDir(test, this.config)));
|
|
19
|
+
writeFileSync('.knapsack-pro/list.json', JSON.stringify(Array.from(paths)));
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
export default ListReporter;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@knapsack-pro/playwright",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "0.1.0",
|
|
5
|
+
"description": "Knapsack Pro Playwright splits Playwright tests across CI nodes and makes sure that tests will run in optimal time on each CI node.",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://github.com/KnapsackPro/knapsack-pro-js.git",
|
|
9
|
+
"directory": "packages/playwright"
|
|
10
|
+
},
|
|
11
|
+
"keywords": [
|
|
12
|
+
"knapsack",
|
|
13
|
+
"knapsack pro",
|
|
14
|
+
"playwright",
|
|
15
|
+
"test suite parallelisation",
|
|
16
|
+
"parallelisation",
|
|
17
|
+
"testing",
|
|
18
|
+
"test",
|
|
19
|
+
"automation",
|
|
20
|
+
"integration",
|
|
21
|
+
"runner",
|
|
22
|
+
"CI"
|
|
23
|
+
],
|
|
24
|
+
"author": "Knapsack Pro <support@knapsackpro.com> (https://knapsackpro.com)",
|
|
25
|
+
"license": "MIT",
|
|
26
|
+
"scripts": {
|
|
27
|
+
"build": "rm -rf lib && tsc && chmod u+x lib/knapsack-playwright.js"
|
|
28
|
+
},
|
|
29
|
+
"files": [
|
|
30
|
+
"lib"
|
|
31
|
+
],
|
|
32
|
+
"bin": {
|
|
33
|
+
"knapsack-pro-playwright": "lib/knapsack-playwright.js"
|
|
34
|
+
},
|
|
35
|
+
"exports": {
|
|
36
|
+
"./package.json": "./package.json",
|
|
37
|
+
"./reporters/batch": "./lib/reporters/batch.js",
|
|
38
|
+
"./reporters/list": "./lib/reporters/list.js"
|
|
39
|
+
},
|
|
40
|
+
"dependencies": {
|
|
41
|
+
"@knapsack-pro/core": "^9.0.0"
|
|
42
|
+
},
|
|
43
|
+
"peerDependencies": {
|
|
44
|
+
"playwright": ">=1.50.0"
|
|
45
|
+
},
|
|
46
|
+
"devDependencies": {
|
|
47
|
+
"@types/node": "^24.9.2",
|
|
48
|
+
"playwright": "^1.56.1",
|
|
49
|
+
"typescript": "^5.9.3"
|
|
50
|
+
}
|
|
51
|
+
}
|