@amazon/vinyl-build-utils 1.0.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/README.md +49 -0
- package/dist/babel/compatTransform.d.ts +20 -0
- package/dist/babel/compatTransform.d.ts.map +1 -0
- package/dist/babel/compatTransform.js +46 -0
- package/dist/browserstack/BrowserStackWorker.d.ts +150 -0
- package/dist/browserstack/BrowserStackWorker.d.ts.map +1 -0
- package/dist/browserstack/BrowserStackWorker.js +280 -0
- package/dist/browserstack/BrowserStackWorkerController.d.ts +103 -0
- package/dist/browserstack/BrowserStackWorkerController.d.ts.map +1 -0
- package/dist/browserstack/BrowserStackWorkerController.js +199 -0
- package/dist/browserstack/browserStackLocal.d.ts +3 -0
- package/dist/browserstack/browserStackLocal.d.ts.map +1 -0
- package/dist/browserstack/browserStackLocal.js +36 -0
- package/dist/browserstack/browserStackRestApi.d.ts +304 -0
- package/dist/browserstack/browserStackRestApi.d.ts.map +1 -0
- package/dist/browserstack/browserStackRestApi.js +121 -0
- package/dist/browserstack/configureReporterApi.d.ts +85 -0
- package/dist/browserstack/configureReporterApi.d.ts.map +1 -0
- package/dist/browserstack/configureReporterApi.js +51 -0
- package/dist/browserstack/runBrowserStack.d.ts +123 -0
- package/dist/browserstack/runBrowserStack.d.ts.map +1 -0
- package/dist/browserstack/runBrowserStack.js +204 -0
- package/dist/esbuild/CompatTransformPlugin.d.ts +6 -0
- package/dist/esbuild/CompatTransformPlugin.d.ts.map +1 -0
- package/dist/esbuild/CompatTransformPlugin.js +59 -0
- package/dist/esbuild/PureExportsPlugin.d.ts +11 -0
- package/dist/esbuild/PureExportsPlugin.d.ts.map +1 -0
- package/dist/esbuild/PureExportsPlugin.js +55 -0
- package/dist/esbuild/TypeDeclarationsPlugin.d.ts +9 -0
- package/dist/esbuild/TypeDeclarationsPlugin.d.ts.map +1 -0
- package/dist/esbuild/TypeDeclarationsPlugin.js +60 -0
- package/dist/esbuild/analyzeExports.d.ts +7 -0
- package/dist/esbuild/analyzeExports.d.ts.map +1 -0
- package/dist/esbuild/analyzeExports.js +78 -0
- package/dist/esbuild/buildAll.d.ts +12 -0
- package/dist/esbuild/buildAll.d.ts.map +1 -0
- package/dist/esbuild/buildAll.js +16 -0
- package/dist/esbuild/optionalEntryPoints.d.ts +8 -0
- package/dist/esbuild/optionalEntryPoints.d.ts.map +1 -0
- package/dist/esbuild/optionalEntryPoints.js +20 -0
- package/dist/express/serve.d.ts +33 -0
- package/dist/express/serve.d.ts.map +1 -0
- package/dist/express/serve.js +31 -0
- package/dist/express/startExpressServer.d.ts +80 -0
- package/dist/express/startExpressServer.d.ts.map +1 -0
- package/dist/express/startExpressServer.js +114 -0
- package/dist/index.d.ts +36 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +35 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/dist/typescript/buildTypeDeclarations.d.ts +47 -0
- package/dist/typescript/buildTypeDeclarations.d.ts.map +1 -0
- package/dist/typescript/buildTypeDeclarations.js +65 -0
- package/dist/typescript/parseTsConfig.d.ts +13 -0
- package/dist/typescript/parseTsConfig.d.ts.map +1 -0
- package/dist/typescript/parseTsConfig.js +23 -0
- package/dist/typescript/replacePathAliases.d.ts +10 -0
- package/dist/typescript/replacePathAliases.d.ts.map +1 -0
- package/dist/typescript/replacePathAliases.js +26 -0
- package/dist/typescript/resolveProjectReferences.d.ts +8 -0
- package/dist/typescript/resolveProjectReferences.d.ts.map +1 -0
- package/dist/typescript/resolveProjectReferences.js +42 -0
- package/dist/typescript/tsc.d.ts +15 -0
- package/dist/typescript/tsc.d.ts.map +1 -0
- package/dist/typescript/tsc.js +28 -0
- package/dist/util/Logger.d.ts +34 -0
- package/dist/util/Logger.d.ts.map +1 -0
- package/dist/util/Logger.js +88 -0
- package/dist/util/TaskQueue.d.ts +30 -0
- package/dist/util/TaskQueue.d.ts.map +1 -0
- package/dist/util/TaskQueue.js +55 -0
- package/dist/util/console.d.ts +22 -0
- package/dist/util/console.d.ts.map +1 -0
- package/dist/util/console.js +58 -0
- package/dist/util/copyFiles.d.ts +33 -0
- package/dist/util/copyFiles.d.ts.map +1 -0
- package/dist/util/copyFiles.js +55 -0
- package/dist/util/extractArgs.d.ts +12 -0
- package/dist/util/extractArgs.d.ts.map +1 -0
- package/dist/util/extractArgs.js +23 -0
- package/dist/util/getRootProjectDir.d.ts +2 -0
- package/dist/util/getRootProjectDir.d.ts.map +1 -0
- package/dist/util/getRootProjectDir.js +14 -0
- package/dist/util/prompt.d.ts +2 -0
- package/dist/util/prompt.d.ts.map +1 -0
- package/dist/util/prompt.js +15 -0
- package/dist/util/sleep.d.ts +6 -0
- package/dist/util/sleep.d.ts.map +1 -0
- package/dist/util/sleep.js +13 -0
- package/dist/util/string.d.ts +22 -0
- package/dist/util/string.d.ts.map +1 -0
- package/dist/util/string.js +35 -0
- package/dist/util/writeIndexFile.d.ts +13 -0
- package/dist/util/writeIndexFile.d.ts.map +1 -0
- package/dist/util/writeIndexFile.js +92 -0
- package/dist/vinyl/buildVinylPackage.d.ts +40 -0
- package/dist/vinyl/buildVinylPackage.d.ts.map +1 -0
- package/dist/vinyl/buildVinylPackage.js +167 -0
- package/dist/vinyl/vinylDefaultBrowserStackOptions.d.ts +25 -0
- package/dist/vinyl/vinylDefaultBrowserStackOptions.d.ts.map +1 -0
- package/dist/vinyl/vinylDefaultBrowserStackOptions.js +28 -0
- package/dist/vinyl/vinylDefaultTscOptions.d.ts +3 -0
- package/dist/vinyl/vinylDefaultTscOptions.d.ts.map +1 -0
- package/dist/vinyl/vinylDefaultTscOptions.js +11 -0
- package/dist/vinyl/vinylSupportedBrowsers.d.ts +18 -0
- package/dist/vinyl/vinylSupportedBrowsers.d.ts.map +1 -0
- package/dist/vinyl/vinylSupportedBrowsers.js +55 -0
- package/package.json +52 -0
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import type { Express } from 'express';
|
|
2
|
+
export interface StartedRequest {
|
|
3
|
+
/**
|
|
4
|
+
* The identifier, provided in the url for the session.
|
|
5
|
+
*/
|
|
6
|
+
readonly id: string;
|
|
7
|
+
/**
|
|
8
|
+
* The total number of specs.
|
|
9
|
+
*/
|
|
10
|
+
readonly totalSpecs: number;
|
|
11
|
+
}
|
|
12
|
+
export interface ProgressRequest {
|
|
13
|
+
/**
|
|
14
|
+
* The identifier, provided in the url for the session.
|
|
15
|
+
*/
|
|
16
|
+
readonly id: string;
|
|
17
|
+
/**
|
|
18
|
+
* The number of specs completed.
|
|
19
|
+
*/
|
|
20
|
+
readonly totalCompleted: number;
|
|
21
|
+
/**
|
|
22
|
+
* The total number of specs.
|
|
23
|
+
*/
|
|
24
|
+
readonly totalSpecs: number;
|
|
25
|
+
/**
|
|
26
|
+
* The console logs.
|
|
27
|
+
*/
|
|
28
|
+
readonly logs: readonly LogEntry[];
|
|
29
|
+
}
|
|
30
|
+
export type LogEntry = [
|
|
31
|
+
level: 'debug' | 'log' | 'info' | 'warn' | 'error',
|
|
32
|
+
/**
|
|
33
|
+
* An iso 8601 date string.
|
|
34
|
+
*/
|
|
35
|
+
dateStr: string,
|
|
36
|
+
/**
|
|
37
|
+
* The log message.
|
|
38
|
+
*/
|
|
39
|
+
message: string
|
|
40
|
+
];
|
|
41
|
+
export interface DoneRequest extends ProgressRequest {
|
|
42
|
+
/**
|
|
43
|
+
* Set session status to either passed or failed.
|
|
44
|
+
*/
|
|
45
|
+
readonly overallStatus: 'passed' | 'failed' | 'incomplete';
|
|
46
|
+
/**
|
|
47
|
+
* Reason for session failure.
|
|
48
|
+
*/
|
|
49
|
+
readonly reason?: string;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Callbacks for the REST API provided to the test reporter.
|
|
53
|
+
*/
|
|
54
|
+
export interface ReportingListener {
|
|
55
|
+
/**
|
|
56
|
+
* Return true if this listener handles the given request id.
|
|
57
|
+
* If the BrowserStack runner is restarted, workers from the previous session may invoke the listener for the new
|
|
58
|
+
* session. Return false to ignore the orphaned testing session.
|
|
59
|
+
*
|
|
60
|
+
* @param id
|
|
61
|
+
*/
|
|
62
|
+
shouldHandleRequest(id: string): boolean;
|
|
63
|
+
/**
|
|
64
|
+
* The suite has begun. Provides the total number of specs.
|
|
65
|
+
* @param request
|
|
66
|
+
*/
|
|
67
|
+
onStarted(request: StartedRequest): void;
|
|
68
|
+
/**
|
|
69
|
+
* One spec has completed.
|
|
70
|
+
*/
|
|
71
|
+
onProgress(request: ProgressRequest): void;
|
|
72
|
+
/**
|
|
73
|
+
* The suite has finished.
|
|
74
|
+
*/
|
|
75
|
+
onDone(request: DoneRequest): void;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Creates a REST API the test reporter can use to notify the browserstack runner of current progress.
|
|
79
|
+
* See Vinyl's `test/browserTestUtil/reporters/RestApiReporter.ts`
|
|
80
|
+
*
|
|
81
|
+
* @param app The Express application.
|
|
82
|
+
* @param listener Callbacks invoked when the API endpoints are called.
|
|
83
|
+
*/
|
|
84
|
+
export declare function configureReportingApi(app: Express, listener: ReportingListener): void;
|
|
85
|
+
//# sourceMappingURL=configureReporterApi.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"configureReporterApi.d.ts","sourceRoot":"","sources":["../../src/browserstack/configureReporterApi.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AAGtC,MAAM,WAAW,cAAc;IAC3B;;OAEG;IACH,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAA;IAEnB;;OAEG;IACH,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAA;CAC9B;AAED,MAAM,WAAW,eAAe;IAC5B;;OAEG;IACH,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAA;IAEnB;;OAEG;IACH,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAA;IAE/B;;OAEG;IACH,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAA;IAE3B;;OAEG;IACH,QAAQ,CAAC,IAAI,EAAE,SAAS,QAAQ,EAAE,CAAA;CACrC;AAED,MAAM,MAAM,QAAQ,GAAG;IACnB,KAAK,EAAE,OAAO,GAAG,KAAK,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO;IAElD;;OAEG;IACH,OAAO,EAAE,MAAM;IAEf;;OAEG;IACH,OAAO,EAAE,MAAM;CAClB,CAAA;AAED,MAAM,WAAW,WAAY,SAAQ,eAAe;IAChD;;OAEG;IACH,QAAQ,CAAC,aAAa,EAAE,QAAQ,GAAG,QAAQ,GAAG,YAAY,CAAA;IAE1D;;OAEG;IACH,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CAC3B;AAED;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAC9B;;;;;;OAMG;IACH,mBAAmB,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAA;IAExC;;;OAGG;IACH,SAAS,CAAC,OAAO,EAAE,cAAc,GAAG,IAAI,CAAA;IAExC;;OAEG;IACH,UAAU,CAAC,OAAO,EAAE,eAAe,GAAG,IAAI,CAAA;IAE1C;;OAEG;IACH,MAAM,CAAC,OAAO,EAAE,WAAW,GAAG,IAAI,CAAA;CACrC;AAED;;;;;;GAMG;AACH,wBAAgB,qBAAqB,CACjC,GAAG,EAAE,OAAO,EACZ,QAAQ,EAAE,iBAAiB,QAwC9B"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
import { json as expressJson } from 'express';
|
|
6
|
+
/**
|
|
7
|
+
* Creates a REST API the test reporter can use to notify the browserstack runner of current progress.
|
|
8
|
+
* See Vinyl's `test/browserTestUtil/reporters/RestApiReporter.ts`
|
|
9
|
+
*
|
|
10
|
+
* @param app The Express application.
|
|
11
|
+
* @param listener Callbacks invoked when the API endpoints are called.
|
|
12
|
+
*/
|
|
13
|
+
export function configureReportingApi(app, listener) {
|
|
14
|
+
app.use(expressJson({ limit: '10mb' }));
|
|
15
|
+
app.post('/report/:id/started', (req, res) => {
|
|
16
|
+
if (listener.shouldHandleRequest(req.params.id)) {
|
|
17
|
+
listener.onStarted({
|
|
18
|
+
id: req.params.id,
|
|
19
|
+
totalSpecs: req.body.totalSpecs,
|
|
20
|
+
});
|
|
21
|
+
res.status(200).send({ ok: true });
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
res.status(400).send({ ok: false });
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
app.post('/report/:id/progress', (req, res) => {
|
|
28
|
+
if (listener.shouldHandleRequest(req.params.id)) {
|
|
29
|
+
listener.onProgress({
|
|
30
|
+
id: req.params.id,
|
|
31
|
+
...req.body,
|
|
32
|
+
});
|
|
33
|
+
res.status(200).send({ ok: true });
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
res.status(400).send({ ok: false });
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
app.post('/report/:id/done', (req, res) => {
|
|
40
|
+
if (listener.shouldHandleRequest(req.params.id)) {
|
|
41
|
+
listener.onDone({
|
|
42
|
+
id: req.params.id,
|
|
43
|
+
...req.body,
|
|
44
|
+
});
|
|
45
|
+
res.status(200).send({ ok: true });
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
res.status(400).send({ ok: false });
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import type { ServerOptions } from '../express/serve';
|
|
2
|
+
import type { BrowserDetails, BrowserStackCredentials, WorkerOptions } from './browserStackRestApi';
|
|
3
|
+
import type { Options as BsLocalOptions } from 'browserstack-local';
|
|
4
|
+
import type { BrowserStackWorkerControllerOptions } from './BrowserStackWorkerController';
|
|
5
|
+
import { LogLevel } from '../util/Logger';
|
|
6
|
+
export interface BrowserStackOptions extends BrowserStackWorkerControllerOptions {
|
|
7
|
+
/**
|
|
8
|
+
* BrowserStack local connection options.
|
|
9
|
+
*/
|
|
10
|
+
readonly local?: Partial<BsLocalOptions>;
|
|
11
|
+
/**
|
|
12
|
+
* Local server configuration.
|
|
13
|
+
*/
|
|
14
|
+
readonly server: ServerOptions;
|
|
15
|
+
/**
|
|
16
|
+
* The BrowserStack credentials, if undefined these will be taken from the environment variables
|
|
17
|
+
* BROWSERSTACK_USERNAME and BROWSERSTACK_ACCESS_KEY.
|
|
18
|
+
* If a `.env` file exists, it will be used to populate environmental variables.
|
|
19
|
+
*/
|
|
20
|
+
readonly credentials?: BrowserStackCredentials | Promise<BrowserStackCredentials>;
|
|
21
|
+
/**
|
|
22
|
+
* The list of browsers to test against.
|
|
23
|
+
* `name` if not provided will be generated using '<device> <os> <browser> <browser_version>'.
|
|
24
|
+
*
|
|
25
|
+
* Valid browsers and devices can be obtained using the SDK config generator at:
|
|
26
|
+
* {@link https://www.browserstack.com/docs/automate/selenium/sdk-config-generator}
|
|
27
|
+
*/
|
|
28
|
+
readonly browsers: readonly WorkerInitOptions[];
|
|
29
|
+
/**
|
|
30
|
+
* Options common to all workers.
|
|
31
|
+
*
|
|
32
|
+
* `build` will default to a unique identifier if not provided.
|
|
33
|
+
*/
|
|
34
|
+
readonly workerCommon?: CommonWorkerInitOptions;
|
|
35
|
+
/**
|
|
36
|
+
* If true, shows continuous progress in the console.
|
|
37
|
+
* If false, progress will be logged in at most 10% increments.
|
|
38
|
+
*
|
|
39
|
+
* Recommended to set to false for CI environments.
|
|
40
|
+
* Default: true when the process.stdout is a terminal.
|
|
41
|
+
*/
|
|
42
|
+
readonly stickyProgress?: boolean;
|
|
43
|
+
/**
|
|
44
|
+
* If true, terminates all workers on the first failure.
|
|
45
|
+
* Default: false
|
|
46
|
+
*/
|
|
47
|
+
readonly stopOnFirstFailure?: boolean;
|
|
48
|
+
/**
|
|
49
|
+
* Sets the log verbosity.
|
|
50
|
+
* Default: LogLevel.INFO
|
|
51
|
+
*/
|
|
52
|
+
readonly logLevel?: LogLevel;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Options to be used as defaults for all workers.
|
|
56
|
+
* Values set on the worker will take priority.
|
|
57
|
+
*/
|
|
58
|
+
export type CommonWorkerInitOptions = Omit<WorkerInitOptions, keyof BrowserDetails>;
|
|
59
|
+
export interface WorkerInitOptions extends Omit<WorkerOptions, 'url'> {
|
|
60
|
+
/**
|
|
61
|
+
* A valid url to navigate the browser to.
|
|
62
|
+
* If not set, the local server URL will be used.
|
|
63
|
+
*/
|
|
64
|
+
readonly url?: string;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Attempts to get the BrowserStackCredentials from the environment.
|
|
68
|
+
*/
|
|
69
|
+
export declare function getEnvBrowserStackCredentials(): BrowserStackCredentials;
|
|
70
|
+
/**
|
|
71
|
+
* When the BrowserStack run has completed, provides the final results.
|
|
72
|
+
*/
|
|
73
|
+
export interface BrowserStackResults {
|
|
74
|
+
readonly passed: boolean;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Runs tests on BrowserStack.
|
|
78
|
+
*
|
|
79
|
+
* This will:
|
|
80
|
+
* - Start a local server including a REST API for serving tests that are expected to report their progress to the
|
|
81
|
+
* service.
|
|
82
|
+
* - Start the BrowserStack local tunnel.
|
|
83
|
+
* - Enqueue workers for each provided browser.
|
|
84
|
+
*
|
|
85
|
+
* @return Returns a Promise with the test results.
|
|
86
|
+
*
|
|
87
|
+
* Example:
|
|
88
|
+
*
|
|
89
|
+
* ```
|
|
90
|
+
* void runBrowserStack({
|
|
91
|
+
* server: {
|
|
92
|
+
* port: 9009,
|
|
93
|
+
* staticDir: './dist/test',
|
|
94
|
+
* },
|
|
95
|
+
* browsers: [
|
|
96
|
+
* {
|
|
97
|
+
* browser: 'chrome',
|
|
98
|
+
* browser_version: 'latest',
|
|
99
|
+
* os: 'OS X',
|
|
100
|
+
* os_version: 'Monterey',
|
|
101
|
+
* },
|
|
102
|
+
* {
|
|
103
|
+
* browser: 'safari',
|
|
104
|
+
* browser_version: 'latest',
|
|
105
|
+
* os: 'OS X',
|
|
106
|
+
* os_version: 'Monterey',
|
|
107
|
+
* },
|
|
108
|
+
* ],
|
|
109
|
+
* workerCommon: {
|
|
110
|
+
* project: 'MyProject',
|
|
111
|
+
* },
|
|
112
|
+
* }).then((result) => {
|
|
113
|
+
* if (!result.passed) process.exit(1)
|
|
114
|
+
* })
|
|
115
|
+
* ```
|
|
116
|
+
*/
|
|
117
|
+
export declare function runBrowserStack(options: BrowserStackOptions): Promise<BrowserStackResults>;
|
|
118
|
+
/**
|
|
119
|
+
* Calls {@link runBrowserStack}, exiting the process when settled.
|
|
120
|
+
* @param options
|
|
121
|
+
*/
|
|
122
|
+
export declare function runBrowserStackAndExit(options: BrowserStackOptions): void;
|
|
123
|
+
//# sourceMappingURL=runBrowserStack.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runBrowserStack.d.ts","sourceRoot":"","sources":["../../src/browserstack/runBrowserStack.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAA;AAErD,OAAO,KAAK,EACR,cAAc,EACd,uBAAuB,EACvB,aAAa,EAChB,MAAM,uBAAuB,CAAA;AAG9B,OAAO,KAAK,EAAE,OAAO,IAAI,cAAc,EAAE,MAAM,oBAAoB,CAAA;AACnE,OAAO,KAAK,EAAE,mCAAmC,EAAE,MAAM,gCAAgC,CAAA;AAIzF,OAAO,EAAU,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AAMjD,MAAM,WAAW,mBAAoB,SAAQ,mCAAmC;IAC5E;;OAEG;IACH,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,CAAC,cAAc,CAAC,CAAA;IAExC;;OAEG;IACH,QAAQ,CAAC,MAAM,EAAE,aAAa,CAAA;IAE9B;;;;OAIG;IACH,QAAQ,CAAC,WAAW,CAAC,EACf,uBAAuB,GACvB,OAAO,CAAC,uBAAuB,CAAC,CAAA;IAEtC;;;;;;OAMG;IACH,QAAQ,CAAC,QAAQ,EAAE,SAAS,iBAAiB,EAAE,CAAA;IAE/C;;;;OAIG;IACH,QAAQ,CAAC,YAAY,CAAC,EAAE,uBAAuB,CAAA;IAE/C;;;;;;OAMG;IACH,QAAQ,CAAC,cAAc,CAAC,EAAE,OAAO,CAAA;IAEjC;;;OAGG;IACH,QAAQ,CAAC,kBAAkB,CAAC,EAAE,OAAO,CAAA;IAErC;;;OAGG;IACH,QAAQ,CAAC,QAAQ,CAAC,EAAE,QAAQ,CAAA;CAC/B;AAED;;;GAGG;AACH,MAAM,MAAM,uBAAuB,GAAG,IAAI,CACtC,iBAAiB,EACjB,MAAM,cAAc,CACvB,CAAA;AAED,MAAM,WAAW,iBAAkB,SAAQ,IAAI,CAAC,aAAa,EAAE,KAAK,CAAC;IACjE;;;OAGG;IACH,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,CAAA;CACxB;AAED;;GAEG;AACH,wBAAgB,6BAA6B,IAAI,uBAAuB,CAavE;AAED;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAChC,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAA;CAC3B;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AACH,wBAAsB,eAAe,CACjC,OAAO,EAAE,mBAAmB,GAC7B,OAAO,CAAC,mBAAmB,CAAC,CAoH9B;AAiBD;;;GAGG;AACH,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,mBAAmB,GAAG,IAAI,CAazE"}
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
import { config as dotEnvConfig } from 'dotenv';
|
|
6
|
+
import express from 'express';
|
|
7
|
+
import { startExpressServer } from '../express/startExpressServer';
|
|
8
|
+
import { configureExpress } from '../express/serve';
|
|
9
|
+
import { BrowserStackAutomateClient } from './browserStackRestApi';
|
|
10
|
+
import { startBrowserStackLocal } from './browserStackLocal';
|
|
11
|
+
import { BrowserStackWorkerController } from './BrowserStackWorkerController';
|
|
12
|
+
import { configureReportingApi } from './configureReporterApi';
|
|
13
|
+
import process from 'node:process';
|
|
14
|
+
import { logger, LogLevel } from '../util/Logger';
|
|
15
|
+
import { ansi, progressBar } from '../util/console';
|
|
16
|
+
import { getRootProjectDir } from '../util/getRootProjectDir';
|
|
17
|
+
import path from 'node:path';
|
|
18
|
+
import crypto from 'node:crypto';
|
|
19
|
+
/**
|
|
20
|
+
* Attempts to get the BrowserStackCredentials from the environment.
|
|
21
|
+
*/
|
|
22
|
+
export function getEnvBrowserStackCredentials() {
|
|
23
|
+
const rootDir = getRootProjectDir();
|
|
24
|
+
if (!rootDir)
|
|
25
|
+
throw new Error('Could not find root project dir from current working directory.');
|
|
26
|
+
dotEnvConfig({
|
|
27
|
+
path: path.resolve(rootDir, '.env'),
|
|
28
|
+
});
|
|
29
|
+
return {
|
|
30
|
+
username: process.env.BROWSERSTACK_USERNAME,
|
|
31
|
+
key: process.env.BROWSERSTACK_ACCESS_KEY,
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Runs tests on BrowserStack.
|
|
36
|
+
*
|
|
37
|
+
* This will:
|
|
38
|
+
* - Start a local server including a REST API for serving tests that are expected to report their progress to the
|
|
39
|
+
* service.
|
|
40
|
+
* - Start the BrowserStack local tunnel.
|
|
41
|
+
* - Enqueue workers for each provided browser.
|
|
42
|
+
*
|
|
43
|
+
* @return Returns a Promise with the test results.
|
|
44
|
+
*
|
|
45
|
+
* Example:
|
|
46
|
+
*
|
|
47
|
+
* ```
|
|
48
|
+
* void runBrowserStack({
|
|
49
|
+
* server: {
|
|
50
|
+
* port: 9009,
|
|
51
|
+
* staticDir: './dist/test',
|
|
52
|
+
* },
|
|
53
|
+
* browsers: [
|
|
54
|
+
* {
|
|
55
|
+
* browser: 'chrome',
|
|
56
|
+
* browser_version: 'latest',
|
|
57
|
+
* os: 'OS X',
|
|
58
|
+
* os_version: 'Monterey',
|
|
59
|
+
* },
|
|
60
|
+
* {
|
|
61
|
+
* browser: 'safari',
|
|
62
|
+
* browser_version: 'latest',
|
|
63
|
+
* os: 'OS X',
|
|
64
|
+
* os_version: 'Monterey',
|
|
65
|
+
* },
|
|
66
|
+
* ],
|
|
67
|
+
* workerCommon: {
|
|
68
|
+
* project: 'MyProject',
|
|
69
|
+
* },
|
|
70
|
+
* }).then((result) => {
|
|
71
|
+
* if (!result.passed) process.exit(1)
|
|
72
|
+
* })
|
|
73
|
+
* ```
|
|
74
|
+
*/
|
|
75
|
+
export async function runBrowserStack(options) {
|
|
76
|
+
// Validate options argument
|
|
77
|
+
if (!options.browsers.length)
|
|
78
|
+
throw new Error('options.browsers is required');
|
|
79
|
+
let done;
|
|
80
|
+
const donePromise = new Promise((r) => (done = r));
|
|
81
|
+
const bsCredentials = (await options.credentials) ?? getEnvBrowserStackCredentials();
|
|
82
|
+
if (!bsCredentials.username || !bsCredentials.key)
|
|
83
|
+
throw new Error('Missing BrowserStack credentials. May be provided via options.credentials, or the environmental ' +
|
|
84
|
+
'variables BROWSERSTACK_USERNAME and BROWSERSTACK_ACCESS_KEY. ' +
|
|
85
|
+
'Environmental variables may be set via a .env file.');
|
|
86
|
+
// Use the explicitly set stickyProgress value, or default to true if the stdout is a terminal.
|
|
87
|
+
const useSticky = options.stickyProgress ?? process.stdout.isTTY;
|
|
88
|
+
logger.level = options.logLevel ?? LogLevel.INFO;
|
|
89
|
+
const localOptions = {
|
|
90
|
+
key: bsCredentials.key,
|
|
91
|
+
logFile: './bStackLogs/local.log',
|
|
92
|
+
...options.local,
|
|
93
|
+
};
|
|
94
|
+
const shutdownLocalTunnel = await startBrowserStackLocal(localOptions);
|
|
95
|
+
const app = express();
|
|
96
|
+
configureExpress(app, options.server);
|
|
97
|
+
const serverHandle = await startExpressServer({ app }, options.server);
|
|
98
|
+
const client = new BrowserStackAutomateClient(bsCredentials);
|
|
99
|
+
const build = `build-${crypto.randomUUID()}`;
|
|
100
|
+
const workerOptions = options.browsers.map((browser) => {
|
|
101
|
+
const name = browser.name ?? generateNameForBrowser(browser);
|
|
102
|
+
// Url precedence:
|
|
103
|
+
const url = browser.url ??
|
|
104
|
+
options.workerCommon?.url ??
|
|
105
|
+
serverHandle.https?.url ??
|
|
106
|
+
serverHandle.http.url;
|
|
107
|
+
return {
|
|
108
|
+
build,
|
|
109
|
+
name,
|
|
110
|
+
...options.workerCommon,
|
|
111
|
+
...browser,
|
|
112
|
+
url,
|
|
113
|
+
};
|
|
114
|
+
});
|
|
115
|
+
const workerController = new BrowserStackWorkerController({ client }, workerOptions, options);
|
|
116
|
+
configureReportingApi(app, workerController);
|
|
117
|
+
const state = workerController.state;
|
|
118
|
+
function createProgressMessage() {
|
|
119
|
+
let failedStr = `failed: ${state.failed}`;
|
|
120
|
+
if (state.failed > 0)
|
|
121
|
+
failedStr = ansi.red + failedStr + ansi.resetColor;
|
|
122
|
+
return (`${ansi.green}passed: ${state.passed}${ansi.resetColor}, ${failedStr}, running: ${state.running}, pending: ${state.pending}\n` +
|
|
123
|
+
progressBar(state.percentComplete));
|
|
124
|
+
}
|
|
125
|
+
let previousDecile = 0;
|
|
126
|
+
workerController.onUpdate = () => {
|
|
127
|
+
if (disposed)
|
|
128
|
+
return;
|
|
129
|
+
const progressStr = createProgressMessage();
|
|
130
|
+
if (useSticky)
|
|
131
|
+
logger.sticky(progressStr);
|
|
132
|
+
else {
|
|
133
|
+
const decile = Math.trunc(state.percentComplete * 10);
|
|
134
|
+
if (decile !== previousDecile) {
|
|
135
|
+
logger.info(progressStr);
|
|
136
|
+
previousDecile = decile;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
if (options.stopOnFirstFailure && state.failed)
|
|
140
|
+
void shutdown();
|
|
141
|
+
if (!state.remaining)
|
|
142
|
+
void shutdown();
|
|
143
|
+
};
|
|
144
|
+
const sigIntHandler = () => {
|
|
145
|
+
logger.info('SIGINT signal received.');
|
|
146
|
+
void shutdown().then(() => {
|
|
147
|
+
process.exit(1);
|
|
148
|
+
});
|
|
149
|
+
};
|
|
150
|
+
process.once('SIGINT', sigIntHandler);
|
|
151
|
+
let disposed = false;
|
|
152
|
+
async function shutdown() {
|
|
153
|
+
if (disposed)
|
|
154
|
+
return;
|
|
155
|
+
disposed = true;
|
|
156
|
+
logger.clearSticky();
|
|
157
|
+
logger.info(createProgressMessage());
|
|
158
|
+
logger.debug('Shutting down');
|
|
159
|
+
process.removeListener('SIGINT', sigIntHandler);
|
|
160
|
+
await workerController.terminate();
|
|
161
|
+
await serverHandle.close();
|
|
162
|
+
await shutdownLocalTunnel();
|
|
163
|
+
// Resolve the promise with the final results:
|
|
164
|
+
const passed = workerController.allPassed;
|
|
165
|
+
if (passed)
|
|
166
|
+
logger.info('✅ All tests passed');
|
|
167
|
+
done({
|
|
168
|
+
passed,
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
workerController.start();
|
|
172
|
+
return await donePromise;
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Creates a session name for the given browser options.
|
|
176
|
+
*/
|
|
177
|
+
function generateNameForBrowser(browser) {
|
|
178
|
+
return [
|
|
179
|
+
browser.device,
|
|
180
|
+
browser.os,
|
|
181
|
+
browser.os_version,
|
|
182
|
+
browser.browser,
|
|
183
|
+
browser.browser_version,
|
|
184
|
+
]
|
|
185
|
+
.filter((str) => str)
|
|
186
|
+
.join(' ');
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Calls {@link runBrowserStack}, exiting the process when settled.
|
|
190
|
+
* @param options
|
|
191
|
+
*/
|
|
192
|
+
export function runBrowserStackAndExit(options) {
|
|
193
|
+
runBrowserStack(options)
|
|
194
|
+
.then((result) => {
|
|
195
|
+
if (!result.passed)
|
|
196
|
+
process.exit(1);
|
|
197
|
+
})
|
|
198
|
+
.catch((error) => {
|
|
199
|
+
console.error(ansi.red +
|
|
200
|
+
String('message' in error ? error.message : error) +
|
|
201
|
+
ansi.resetColor);
|
|
202
|
+
process.exit(1);
|
|
203
|
+
});
|
|
204
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { Plugin } from 'esbuild';
|
|
2
|
+
export interface CompatTransformPluginOptions {
|
|
3
|
+
readonly enabled?: boolean;
|
|
4
|
+
}
|
|
5
|
+
export declare function compatTransformPlugin(options?: CompatTransformPluginOptions): Plugin;
|
|
6
|
+
//# sourceMappingURL=CompatTransformPlugin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CompatTransformPlugin.d.ts","sourceRoot":"","sources":["../../src/esbuild/CompatTransformPlugin.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,MAAM,EAAe,MAAM,SAAS,CAAA;AAKlD,MAAM,WAAW,4BAA4B;IACzC,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,CAAA;CAC7B;AAYD,wBAAgB,qBAAqB,CACjC,OAAO,GAAE,4BAAiC,GAC3C,MAAM,CAoDR"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
import { compatTransform } from '../babel/compatTransform';
|
|
6
|
+
import path from 'path';
|
|
7
|
+
import { logger } from '../util/Logger';
|
|
8
|
+
/**
|
|
9
|
+
* Changes a path's file extension.
|
|
10
|
+
*/
|
|
11
|
+
function changeExtension(filePath, newExtension) {
|
|
12
|
+
const dir = path.dirname(filePath);
|
|
13
|
+
const ext = path.extname(filePath);
|
|
14
|
+
const base = path.basename(filePath, ext);
|
|
15
|
+
return path.join(dir, base) + '.' + newExtension;
|
|
16
|
+
}
|
|
17
|
+
export function compatTransformPlugin(options = {}) {
|
|
18
|
+
return {
|
|
19
|
+
name: 'CompatTransformPlugin',
|
|
20
|
+
setup(build) {
|
|
21
|
+
build.onEnd(async (result) => {
|
|
22
|
+
if (options.enabled === false || result.errors.length)
|
|
23
|
+
return;
|
|
24
|
+
if (!result.metafile) {
|
|
25
|
+
return {
|
|
26
|
+
errors: [
|
|
27
|
+
{
|
|
28
|
+
text: 'CompatTransformPlugin requires metafile: true',
|
|
29
|
+
},
|
|
30
|
+
],
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
const jsOutputs = Object.keys(result.metafile.outputs).filter((f) => /\.([cm])?js$/i.test(f));
|
|
34
|
+
await Promise.all(jsOutputs.map(async (srcPath) => {
|
|
35
|
+
const destPath = changeExtension(srcPath, 'es5.js');
|
|
36
|
+
logger.debug(`babel: transpiling '${srcPath}' -> '${destPath}' ...`);
|
|
37
|
+
try {
|
|
38
|
+
await compatTransform({
|
|
39
|
+
src: srcPath,
|
|
40
|
+
dest: destPath,
|
|
41
|
+
});
|
|
42
|
+
logger.info(`babel: '${destPath}'`);
|
|
43
|
+
}
|
|
44
|
+
catch (e) {
|
|
45
|
+
return {
|
|
46
|
+
errors: [
|
|
47
|
+
{
|
|
48
|
+
text: `babel failed: ${e}`,
|
|
49
|
+
location: { file: srcPath },
|
|
50
|
+
detail: e,
|
|
51
|
+
},
|
|
52
|
+
],
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
}));
|
|
56
|
+
});
|
|
57
|
+
},
|
|
58
|
+
};
|
|
59
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { OnLoadArgs, OnLoadResult, Plugin } from 'esbuild';
|
|
2
|
+
/**
|
|
3
|
+
* Adds a PURE annotation to call expressions and `new` expressions
|
|
4
|
+
* inside object literals that are not within any function-like scope.
|
|
5
|
+
* This allows exported config-like structures to be tree-shaken safely
|
|
6
|
+
* when not referenced.
|
|
7
|
+
*/
|
|
8
|
+
export declare const pureExportsPlugin: Plugin;
|
|
9
|
+
export declare function onLoad(args: OnLoadArgs): Promise<OnLoadResult | null>;
|
|
10
|
+
export declare function annotatePureComments(source: string): string;
|
|
11
|
+
//# sourceMappingURL=PureExportsPlugin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PureExportsPlugin.d.ts","sourceRoot":"","sources":["../../src/esbuild/PureExportsPlugin.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAU,UAAU,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AAQvE;;;;;GAKG;AACH,eAAO,MAAM,iBAAiB,EAAE,MAK/B,CAAA;AAED,wBAAsB,MAAM,CAAC,IAAI,EAAE,UAAU,GAAG,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC,CAM3E;AAED,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAmB3D"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
import { readFile } from 'fs/promises';
|
|
6
|
+
import { extname } from 'path';
|
|
7
|
+
import { parse } from '@babel/parser';
|
|
8
|
+
import MagicString from 'magic-string';
|
|
9
|
+
import { traverse } from '@babel/core';
|
|
10
|
+
/**
|
|
11
|
+
* Adds a PURE annotation to call expressions and `new` expressions
|
|
12
|
+
* inside object literals that are not within any function-like scope.
|
|
13
|
+
* This allows exported config-like structures to be tree-shaken safely
|
|
14
|
+
* when not referenced.
|
|
15
|
+
*/
|
|
16
|
+
export const pureExportsPlugin = {
|
|
17
|
+
name: 'pure-exports',
|
|
18
|
+
setup(build) {
|
|
19
|
+
build.onLoad({ filter: /\.[jt]sx?$/ }, onLoad);
|
|
20
|
+
},
|
|
21
|
+
};
|
|
22
|
+
export async function onLoad(args) {
|
|
23
|
+
const source = await readFile(args.path, 'utf8');
|
|
24
|
+
return {
|
|
25
|
+
contents: annotatePureComments(source),
|
|
26
|
+
loader: extname(args.path).slice(1),
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
export function annotatePureComments(source) {
|
|
30
|
+
const ast = parse(source, {
|
|
31
|
+
sourceType: 'module',
|
|
32
|
+
plugins: ['typescript', 'jsx'],
|
|
33
|
+
ranges: true,
|
|
34
|
+
});
|
|
35
|
+
const ms = new MagicString(source);
|
|
36
|
+
traverse(ast, {
|
|
37
|
+
CallExpression(path) {
|
|
38
|
+
maybeAnnotate(path, ms);
|
|
39
|
+
},
|
|
40
|
+
NewExpression(path) {
|
|
41
|
+
maybeAnnotate(path, ms);
|
|
42
|
+
},
|
|
43
|
+
});
|
|
44
|
+
return ms.toString();
|
|
45
|
+
}
|
|
46
|
+
function maybeAnnotate(path, ms) {
|
|
47
|
+
const { node } = path;
|
|
48
|
+
if (node.start == null)
|
|
49
|
+
return;
|
|
50
|
+
// Disallow annotation if the object literal is within any function-like scope
|
|
51
|
+
if (path.findParent((p) => p.isFunctionParent()))
|
|
52
|
+
return;
|
|
53
|
+
// Annotate as PURE
|
|
54
|
+
ms.prependLeft(node.start, '/* @__PURE__ */ ');
|
|
55
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Plugin } from 'esbuild';
|
|
2
|
+
import { type TypeDeclarationOptions } from '../typescript/buildTypeDeclarations';
|
|
3
|
+
/**
|
|
4
|
+
* A plugin to emit type declarations after each build.
|
|
5
|
+
*
|
|
6
|
+
* @param options
|
|
7
|
+
*/
|
|
8
|
+
export declare function tscPlugin(options?: TypeDeclarationOptions): Plugin;
|
|
9
|
+
//# sourceMappingURL=TypeDeclarationsPlugin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TypeDeclarationsPlugin.d.ts","sourceRoot":"","sources":["../../src/esbuild/TypeDeclarationsPlugin.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAA+B,MAAM,EAAe,MAAM,SAAS,CAAA;AAG/E,OAAO,EAEH,KAAK,sBAAsB,EAC9B,MAAM,qCAAqC,CAAA;AAE5C;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,OAAO,GAAE,sBAA2B,GAAG,MAAM,CA4BtE"}
|