@brillout/test-e2e 0.1.3
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/bin.js +2 -0
- package/dist/Logs.d.ts +29 -0
- package/dist/Logs.js +77 -0
- package/dist/buildTs.d.ts +2 -0
- package/dist/buildTs.js +22 -0
- package/dist/chai/JestChaiExpect.d.ts +2 -0
- package/dist/chai/JestChaiExpect.js +27 -0
- package/dist/chai/expect.d.ts +2 -0
- package/dist/chai/expect.js +30 -0
- package/dist/chai/types.d.ts +15 -0
- package/dist/chai/types.js +2 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +43 -0
- package/dist/editFile.d.ts +6 -0
- package/dist/editFile.js +49 -0
- package/dist/findTestFiles.d.ts +3 -0
- package/dist/findTestFiles.js +26 -0
- package/dist/getBrowser.d.ts +3 -0
- package/dist/getBrowser.js +15 -0
- package/dist/getTestInfo.d.ts +21 -0
- package/dist/getTestInfo.js +14 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +24 -0
- package/dist/logProgress.d.ts +2 -0
- package/dist/logProgress.js +41 -0
- package/dist/page.d.ts +3 -0
- package/dist/page.js +13 -0
- package/dist/runTestSuites.d.ts +6 -0
- package/dist/runTestSuites.js +41 -0
- package/dist/runTests.d.ts +3 -0
- package/dist/runTests.js +111 -0
- package/dist/setup.d.ts +36 -0
- package/dist/setup.js +465 -0
- package/dist/test.d.ts +2 -0
- package/dist/test.js +15 -0
- package/dist/utils/assert.d.ts +14 -0
- package/dist/utils/assert.js +72 -0
- package/dist/utils/createErrorWithCleanStackTrace.d.ts +2 -0
- package/dist/utils/createErrorWithCleanStackTrace.js +43 -0
- package/dist/utils/findFiles.d.ts +7 -0
- package/dist/utils/findFiles.js +46 -0
- package/dist/utils/humanizeTime.d.ts +1 -0
- package/dist/utils/humanizeTime.js +15 -0
- package/dist/utils/index.d.ts +6 -0
- package/dist/utils/index.js +22 -0
- package/dist/utils/isTTY.d.ts +1 -0
- package/dist/utils/isTTY.js +5 -0
- package/dist/utils/projectInfo.d.ts +5 -0
- package/dist/utils/projectInfo.js +8 -0
- package/dist/utils/runCommand.d.ts +6 -0
- package/dist/utils/runCommand.js +46 -0
- package/dist/utils/sleep.d.ts +2 -0
- package/dist/utils/sleep.js +7 -0
- package/package.json +37 -0
package/bin.js
ADDED
package/dist/Logs.d.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export { expectBrowserError };
|
|
2
|
+
export declare const Logs: {
|
|
3
|
+
add: typeof add;
|
|
4
|
+
flush: typeof flush;
|
|
5
|
+
clear: typeof clear;
|
|
6
|
+
getBrowserErrors: typeof getBrowserErrors;
|
|
7
|
+
flushEagerly: boolean;
|
|
8
|
+
};
|
|
9
|
+
declare type LogType = 'stdout' | 'stderr' | 'Browser Error' | 'Browser Log' | 'Run Start' | 'Jest' | 'process' | 'Connection Error';
|
|
10
|
+
declare type TestContext = null | {
|
|
11
|
+
testName: string;
|
|
12
|
+
cmd: string;
|
|
13
|
+
};
|
|
14
|
+
declare type LogEntry = {
|
|
15
|
+
logType: LogType;
|
|
16
|
+
logText: string;
|
|
17
|
+
logTimestamp: string;
|
|
18
|
+
testContext: TestContext;
|
|
19
|
+
isExpectedError: boolean;
|
|
20
|
+
};
|
|
21
|
+
declare function getBrowserErrors(): LogEntry[];
|
|
22
|
+
declare function clear(): void;
|
|
23
|
+
declare function flush(): void;
|
|
24
|
+
declare function add({ logType, logText, testContext }: {
|
|
25
|
+
logType: LogType;
|
|
26
|
+
logText: string;
|
|
27
|
+
testContext: TestContext;
|
|
28
|
+
}): void;
|
|
29
|
+
declare function expectBrowserError(browserLogFilter: (browserLog: LogEntry) => boolean): void;
|
package/dist/Logs.js
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Logs = exports.expectBrowserError = void 0;
|
|
4
|
+
exports.Logs = {
|
|
5
|
+
add,
|
|
6
|
+
flush,
|
|
7
|
+
clear,
|
|
8
|
+
getBrowserErrors,
|
|
9
|
+
flushEagerly: false,
|
|
10
|
+
};
|
|
11
|
+
const utils_1 = require("./utils");
|
|
12
|
+
const kolorist_1 = require("kolorist");
|
|
13
|
+
let logEntries = [];
|
|
14
|
+
let logEntriesNotPrinted = [];
|
|
15
|
+
function getBrowserErrors() {
|
|
16
|
+
return logEntries.filter(({ logType, isExpectedError }) => logType === 'Browser Error' && !isExpectedError);
|
|
17
|
+
}
|
|
18
|
+
function clear() {
|
|
19
|
+
logEntries = [];
|
|
20
|
+
logEntriesNotPrinted = [];
|
|
21
|
+
}
|
|
22
|
+
function flush() {
|
|
23
|
+
logEntriesNotPrinted.forEach((logEntry) => printLog(logEntry));
|
|
24
|
+
logEntriesNotPrinted = [];
|
|
25
|
+
}
|
|
26
|
+
function add({ logType, logText, testContext }) {
|
|
27
|
+
const logTimestamp = getTimestamp();
|
|
28
|
+
const logEntry = {
|
|
29
|
+
logType,
|
|
30
|
+
logText,
|
|
31
|
+
testContext,
|
|
32
|
+
logTimestamp,
|
|
33
|
+
isExpectedError: false,
|
|
34
|
+
};
|
|
35
|
+
logEntriesNotPrinted.push(logEntry);
|
|
36
|
+
logEntries.push(logEntry);
|
|
37
|
+
if (exports.Logs.flushEagerly) {
|
|
38
|
+
flush();
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
function expectBrowserError(browserLogFilter) {
|
|
42
|
+
const found = !!logEntries.find((logEntry) => {
|
|
43
|
+
if (browserLogFilter(logEntry)) {
|
|
44
|
+
logEntry.isExpectedError = true;
|
|
45
|
+
return true;
|
|
46
|
+
}
|
|
47
|
+
return false;
|
|
48
|
+
});
|
|
49
|
+
//expect(found).toBe(true)
|
|
50
|
+
(0, utils_1.assert)(found === true);
|
|
51
|
+
}
|
|
52
|
+
exports.expectBrowserError = expectBrowserError;
|
|
53
|
+
function getTimestamp() {
|
|
54
|
+
const now = new Date();
|
|
55
|
+
const time = now.toTimeString().split(' ')[0];
|
|
56
|
+
const milliseconds = now.getTime().toString().split('').slice(-3).join('');
|
|
57
|
+
const timestamp = time + '.' + milliseconds;
|
|
58
|
+
return timestamp;
|
|
59
|
+
}
|
|
60
|
+
function printLog(logEntry) {
|
|
61
|
+
const { logType, logText, logTimestamp, testContext } = logEntry;
|
|
62
|
+
let prefix = logType;
|
|
63
|
+
if (logType === 'stderr' || logType === 'Browser Error')
|
|
64
|
+
prefix = (0, kolorist_1.bold)((0, kolorist_1.red)(logType));
|
|
65
|
+
if (logType === 'stdout' || logType === 'Browser Log')
|
|
66
|
+
prefix = (0, kolorist_1.bold)((0, kolorist_1.blue)(logType));
|
|
67
|
+
let msg = logText;
|
|
68
|
+
if (!msg)
|
|
69
|
+
msg = ''; // don't know why but sometimes `logText` is `undefined`
|
|
70
|
+
if (!msg.endsWith('\n'))
|
|
71
|
+
msg = msg + '\n';
|
|
72
|
+
if (testContext) {
|
|
73
|
+
const { testName, cmd } = testContext;
|
|
74
|
+
msg = `[${testName}][${cmd}] ${msg}`;
|
|
75
|
+
}
|
|
76
|
+
process.stderr.write(`[${logTimestamp}][${prefix}]${msg}`);
|
|
77
|
+
}
|
package/dist/buildTs.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.buildTs = void 0;
|
|
7
|
+
const esbuild_1 = __importDefault(require("esbuild"));
|
|
8
|
+
async function buildTs(entry, outfile) {
|
|
9
|
+
await esbuild_1.default.build({
|
|
10
|
+
platform: 'node',
|
|
11
|
+
entryPoints: [entry],
|
|
12
|
+
sourcemap: true,
|
|
13
|
+
outfile,
|
|
14
|
+
logLevel: 'warning',
|
|
15
|
+
format: 'esm',
|
|
16
|
+
target: 'es2020',
|
|
17
|
+
bundle: true,
|
|
18
|
+
external: ['./node_modules/*', '@brillout/test-e2e'],
|
|
19
|
+
minify: false,
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
exports.buildTs = buildTs;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.JestChaiExpect = void 0;
|
|
4
|
+
// Copied from https://github.com/vitest-dev/vitest/blob/f3524602ccc678badaae6bc5c3945008d8cfd82a/packages/vitest/src/integrations/chai/jest-expect.ts
|
|
5
|
+
const JestChaiExpect = (chai, utils) => {
|
|
6
|
+
function def(name, fn) {
|
|
7
|
+
utils.addMethod(chai.Assertion.prototype, name, fn);
|
|
8
|
+
}
|
|
9
|
+
def('toContain', function (item) {
|
|
10
|
+
return this.contain(item);
|
|
11
|
+
});
|
|
12
|
+
def('toMatch', function (item) {
|
|
13
|
+
return this.match(item);
|
|
14
|
+
});
|
|
15
|
+
def('toBe', function (item) {
|
|
16
|
+
return this.equal(item);
|
|
17
|
+
});
|
|
18
|
+
def('toBeTruthy', function () {
|
|
19
|
+
const obj = utils.flag(this, 'object');
|
|
20
|
+
this.assert(Boolean(obj), 'expected #{this} to be truthy', 'expected #{this} to not be truthy', obj);
|
|
21
|
+
});
|
|
22
|
+
def('toBeFalsy', function () {
|
|
23
|
+
const obj = utils.flag(this, 'object');
|
|
24
|
+
this.assert(!obj, 'expected #{this} to be falsy', 'expected #{this} to not be falsy', obj);
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
exports.JestChaiExpect = JestChaiExpect;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.expect = void 0;
|
|
27
|
+
const JestChaiExpect_1 = require("./JestChaiExpect");
|
|
28
|
+
const chai = __importStar(require("chai"));
|
|
29
|
+
chai.use(JestChaiExpect_1.JestChaiExpect);
|
|
30
|
+
exports.expect = chai.expect;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export type { ChaiPlugin };
|
|
2
|
+
export type { Expect };
|
|
3
|
+
import type { use as chaiUse } from 'chai';
|
|
4
|
+
declare type FirstFunctionArgument<T> = T extends (arg: infer A) => unknown ? A : never;
|
|
5
|
+
declare type ChaiPlugin = FirstFunctionArgument<typeof chaiUse>;
|
|
6
|
+
declare type Assertion = Chai.Assertion & {
|
|
7
|
+
not: Assertion;
|
|
8
|
+
toContain: Assertion['contain'];
|
|
9
|
+
toMatch: Assertion['match'];
|
|
10
|
+
toBe: Assertion['equal'];
|
|
11
|
+
toBeFalsy(): void;
|
|
12
|
+
toBeTruthy(): void;
|
|
13
|
+
toBee: Assertion['equal'];
|
|
14
|
+
};
|
|
15
|
+
declare type Expect = (value: any) => Assertion;
|
package/dist/cli.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import 'source-map-support/register';
|
package/dist/cli.js
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
// @ts-ignore
|
|
4
|
+
require("source-map-support/register");
|
|
5
|
+
const runTestSuites_1 = require("./runTestSuites");
|
|
6
|
+
initPromiseRejectionHandler();
|
|
7
|
+
cli();
|
|
8
|
+
function cli() {
|
|
9
|
+
const { filter, debug } = parseArgs();
|
|
10
|
+
(0, runTestSuites_1.runTestSuites)({ filter, debug });
|
|
11
|
+
}
|
|
12
|
+
function parseArgs() {
|
|
13
|
+
let debug = false;
|
|
14
|
+
const terms = [];
|
|
15
|
+
let exclude = false;
|
|
16
|
+
process.argv.slice(2).forEach((arg) => {
|
|
17
|
+
if (arg === '--debug') {
|
|
18
|
+
debug = true;
|
|
19
|
+
}
|
|
20
|
+
else if (arg === '--exclude') {
|
|
21
|
+
exclude = true;
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
terms.push(arg);
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
const filter = terms.length === 0
|
|
28
|
+
? null
|
|
29
|
+
: {
|
|
30
|
+
terms,
|
|
31
|
+
exclude,
|
|
32
|
+
};
|
|
33
|
+
return {
|
|
34
|
+
filter,
|
|
35
|
+
debug,
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
function initPromiseRejectionHandler() {
|
|
39
|
+
process.on('unhandledRejection', function (err) {
|
|
40
|
+
console.error(err);
|
|
41
|
+
process.exit(1);
|
|
42
|
+
});
|
|
43
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { editFile };
|
|
2
|
+
export { editFileRevert };
|
|
3
|
+
export { editFileAssertReverted };
|
|
4
|
+
declare function editFile(filePathRelative: string, replacer: (fileContent: string) => string): void;
|
|
5
|
+
declare function editFileRevert(): void;
|
|
6
|
+
declare function editFileAssertReverted(): void;
|
package/dist/editFile.js
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.editFileAssertReverted = exports.editFileRevert = exports.editFile = void 0;
|
|
7
|
+
const fs_1 = __importDefault(require("fs"));
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
const utils_1 = require("./utils");
|
|
10
|
+
const getTestInfo_1 = require("./getTestInfo");
|
|
11
|
+
const filesContentOriginal = {};
|
|
12
|
+
function editFile(filePathRelative, replacer) {
|
|
13
|
+
const filePath = getFilePath(filePathRelative);
|
|
14
|
+
const fileContent = fs_1.default.readFileSync(filePath, 'utf8');
|
|
15
|
+
if (!(filePath in filesContentOriginal)) {
|
|
16
|
+
filesContentOriginal[filePath] = fileContent;
|
|
17
|
+
}
|
|
18
|
+
const fileContentNew = replacer(fileContent);
|
|
19
|
+
// expect(fileContentNew).not.toBe(fileContent)
|
|
20
|
+
(0, utils_1.assert)(fileContentNew !== fileContent);
|
|
21
|
+
fs_1.default.writeFileSync(filePath, fileContentNew);
|
|
22
|
+
}
|
|
23
|
+
exports.editFile = editFile;
|
|
24
|
+
function editFileRevert() {
|
|
25
|
+
Object.entries(filesContentOriginal).forEach(([filePath, fileContent]) => {
|
|
26
|
+
fs_1.default.writeFileSync(filePath, fileContent);
|
|
27
|
+
delete filesContentOriginal[filePath];
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
exports.editFileRevert = editFileRevert;
|
|
31
|
+
function editFileAssertReverted() {
|
|
32
|
+
const filesDirty = Object.keys(filesContentOriginal);
|
|
33
|
+
try {
|
|
34
|
+
// expect(filesDirty).toEqual([])
|
|
35
|
+
(0, utils_1.assert)(filesDirty.length === 0);
|
|
36
|
+
}
|
|
37
|
+
catch (err) {
|
|
38
|
+
editFileRevert();
|
|
39
|
+
throw err;
|
|
40
|
+
}
|
|
41
|
+
(0, utils_1.assert)(filesDirty.length === 0);
|
|
42
|
+
}
|
|
43
|
+
exports.editFileAssertReverted = editFileAssertReverted;
|
|
44
|
+
function getFilePath(filePathRelative) {
|
|
45
|
+
const { testFile } = (0, getTestInfo_1.getTestInfo)();
|
|
46
|
+
const cwd = path_1.default.dirname(testFile);
|
|
47
|
+
const filePath = require.resolve(filePathRelative, { paths: [cwd] });
|
|
48
|
+
return filePath;
|
|
49
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.findTestFiles = void 0;
|
|
7
|
+
const path_1 = __importDefault(require("path"));
|
|
8
|
+
const utils_1 = require("./utils");
|
|
9
|
+
const fs_1 = __importDefault(require("fs"));
|
|
10
|
+
const cwd = process.cwd();
|
|
11
|
+
// Unit tests `**/*.spec.*` are handled by Vitesse
|
|
12
|
+
const testFilenamePattern = '**/*.test.ts';
|
|
13
|
+
async function findTestFiles(findFilter) {
|
|
14
|
+
if (process.env.TEST_FILES) {
|
|
15
|
+
const testFiles = process.env.TEST_FILES.split(' ').map((filePathRelative) => path_1.default.join(cwd, filePathRelative));
|
|
16
|
+
testFiles.forEach((testFile) => {
|
|
17
|
+
(0, utils_1.assert)(fs_1.default.existsSync(testFile), testFile);
|
|
18
|
+
});
|
|
19
|
+
return testFiles;
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
const testFiles = (0, utils_1.findFiles)(testFilenamePattern, findFilter);
|
|
23
|
+
return testFiles;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
exports.findTestFiles = findTestFiles;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getBrowser = void 0;
|
|
4
|
+
const playwright_chromium_1 = require("playwright-chromium");
|
|
5
|
+
const logProgress_1 = require("./logProgress");
|
|
6
|
+
let browser;
|
|
7
|
+
async function getBrowser() {
|
|
8
|
+
if (!browser) {
|
|
9
|
+
const done = (0, logProgress_1.logProgress)('Launch Browser', true);
|
|
10
|
+
browser = await playwright_chromium_1.chromium.launch({ headless: true });
|
|
11
|
+
done();
|
|
12
|
+
}
|
|
13
|
+
return browser;
|
|
14
|
+
}
|
|
15
|
+
exports.getBrowser = getBrowser;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export { getTestInfo };
|
|
2
|
+
export { setTestInfo };
|
|
3
|
+
import type { Page } from 'playwright-chromium';
|
|
4
|
+
declare type TestInfo = {
|
|
5
|
+
testFile: string;
|
|
6
|
+
tests?: {
|
|
7
|
+
testDesc: string;
|
|
8
|
+
testFn: Function;
|
|
9
|
+
}[];
|
|
10
|
+
testCmd?: string;
|
|
11
|
+
testTimeout?: number;
|
|
12
|
+
hasStartedRunning?: boolean;
|
|
13
|
+
runWasCalled?: true;
|
|
14
|
+
skipped?: string;
|
|
15
|
+
beforeAll?: () => Promise<void>;
|
|
16
|
+
afterAll?: () => Promise<void>;
|
|
17
|
+
afterEach?: (hasFailed: boolean) => void;
|
|
18
|
+
page?: Page;
|
|
19
|
+
};
|
|
20
|
+
declare function getTestInfo(): TestInfo;
|
|
21
|
+
declare function setTestInfo(testInfo_: null | TestInfo): void;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.setTestInfo = exports.getTestInfo = void 0;
|
|
4
|
+
const utils_1 = require("./utils");
|
|
5
|
+
let testInfo = null;
|
|
6
|
+
function getTestInfo() {
|
|
7
|
+
(0, utils_1.assert)(testInfo);
|
|
8
|
+
return testInfo;
|
|
9
|
+
}
|
|
10
|
+
exports.getTestInfo = getTestInfo;
|
|
11
|
+
function setTestInfo(testInfo_) {
|
|
12
|
+
testInfo = testInfo_;
|
|
13
|
+
}
|
|
14
|
+
exports.setTestInfo = setTestInfo;
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.page = exports.test = exports.expect = void 0;
|
|
18
|
+
__exportStar(require("./setup"), exports);
|
|
19
|
+
var expect_1 = require("./chai/expect");
|
|
20
|
+
Object.defineProperty(exports, "expect", { enumerable: true, get: function () { return expect_1.expect; } });
|
|
21
|
+
var test_1 = require("./test");
|
|
22
|
+
Object.defineProperty(exports, "test", { enumerable: true, get: function () { return test_1.test; } });
|
|
23
|
+
var page_1 = require("./page");
|
|
24
|
+
Object.defineProperty(exports, "page", { enumerable: true, get: function () { return page_1.page; } });
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.logProgress = void 0;
|
|
4
|
+
const getTestInfo_1 = require("./getTestInfo");
|
|
5
|
+
const utils_1 = require("./utils");
|
|
6
|
+
const iconSuccess = '🟢';
|
|
7
|
+
const iconPending = '🟠';
|
|
8
|
+
const iconFail = '🔴';
|
|
9
|
+
function logProgress(text, isSetup) {
|
|
10
|
+
const prefix = getPrefix(isSetup);
|
|
11
|
+
if (utils_1.isTTY) {
|
|
12
|
+
const done = () => { };
|
|
13
|
+
return done;
|
|
14
|
+
}
|
|
15
|
+
process.stdout.write(`${prefix}${iconPending} ${text}`);
|
|
16
|
+
let alreadyDone = false;
|
|
17
|
+
const done = (failed) => {
|
|
18
|
+
if (alreadyDone)
|
|
19
|
+
return;
|
|
20
|
+
alreadyDone = true;
|
|
21
|
+
clear();
|
|
22
|
+
const iconDone = failed ? iconFail : iconSuccess;
|
|
23
|
+
process.stdout.write(`${prefix}${iconDone} ${text}\n`);
|
|
24
|
+
};
|
|
25
|
+
return done;
|
|
26
|
+
}
|
|
27
|
+
exports.logProgress = logProgress;
|
|
28
|
+
function getPrefix(isSetup) {
|
|
29
|
+
if (isSetup) {
|
|
30
|
+
return '';
|
|
31
|
+
}
|
|
32
|
+
if (!(0, getTestInfo_1.getTestInfo)()) {
|
|
33
|
+
return '';
|
|
34
|
+
}
|
|
35
|
+
return ' | ';
|
|
36
|
+
}
|
|
37
|
+
function clear() {
|
|
38
|
+
// @ts-ignore
|
|
39
|
+
process.stdout.clearLine();
|
|
40
|
+
process.stdout.cursorTo(0);
|
|
41
|
+
}
|
package/dist/page.d.ts
ADDED
package/dist/page.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.page = void 0;
|
|
4
|
+
const utils_1 = require("./utils");
|
|
5
|
+
const getTestInfo_1 = require("./getTestInfo");
|
|
6
|
+
const page = new Proxy({}, {
|
|
7
|
+
get(_, prop) {
|
|
8
|
+
const { page } = (0, getTestInfo_1.getTestInfo)();
|
|
9
|
+
(0, utils_1.assert)(page);
|
|
10
|
+
return page[prop];
|
|
11
|
+
},
|
|
12
|
+
});
|
|
13
|
+
exports.page = page;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.runTestSuites = void 0;
|
|
7
|
+
const utils_1 = require("./utils");
|
|
8
|
+
const fs_1 = __importDefault(require("fs"));
|
|
9
|
+
const getTestInfo_1 = require("./getTestInfo");
|
|
10
|
+
const runTests_1 = require("./runTests");
|
|
11
|
+
const getBrowser_1 = require("./getBrowser");
|
|
12
|
+
const buildTs_1 = require("./buildTs");
|
|
13
|
+
const findTestFiles_1 = require("./findTestFiles");
|
|
14
|
+
async function runTestSuites({ filter, debug }) {
|
|
15
|
+
const testFiles = await (0, findTestFiles_1.findTestFiles)(filter);
|
|
16
|
+
const browser = await (0, getBrowser_1.getBrowser)();
|
|
17
|
+
for (const testFile of testFiles) {
|
|
18
|
+
(0, utils_1.assert)(testFile.endsWith('.ts'));
|
|
19
|
+
const testFileJs = testFile.replace('.ts', '.mjs');
|
|
20
|
+
await (0, buildTs_1.buildTs)(testFile, testFileJs);
|
|
21
|
+
(0, getTestInfo_1.setTestInfo)({ testFile });
|
|
22
|
+
try {
|
|
23
|
+
await import(workaroundBug(testFileJs));
|
|
24
|
+
await (0, runTests_1.runTests)(browser);
|
|
25
|
+
}
|
|
26
|
+
finally {
|
|
27
|
+
if (!debug) {
|
|
28
|
+
fs_1.default.unlinkSync(`${testFileJs}`);
|
|
29
|
+
fs_1.default.unlinkSync(`${testFileJs}.map`);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
(0, getTestInfo_1.setTestInfo)(null);
|
|
33
|
+
(0, utils_1.assert)(testFileJs.endsWith('.mjs'));
|
|
34
|
+
}
|
|
35
|
+
await browser.close();
|
|
36
|
+
}
|
|
37
|
+
exports.runTestSuites = runTestSuites;
|
|
38
|
+
// https://stackoverflow.com/questions/69665780/error-err-unsupported-esm-url-scheme-only-file-and-data-urls-are-supported-by/70057245#70057245
|
|
39
|
+
function workaroundBug(testFileJs) {
|
|
40
|
+
return `file://${testFileJs}`;
|
|
41
|
+
}
|