@intuned/runtime-dev 0.0.1-testing.0 → 0.0.1

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.
Files changed (131) hide show
  1. package/.vite/deps_temp_01af7156/package.json +3 -0
  2. package/.vscode/extensions.json +3 -0
  3. package/.vscode/launch.json +102 -0
  4. package/.vscode/settings.json +12 -0
  5. package/WebTemplate/controllers/authSessions/create.ts +1 -1
  6. package/WebTemplate/controllers/runApi/helpers.ts +3 -1
  7. package/package.json +3 -3
  8. package/playwright.config.ts +48 -0
  9. package/src/commands/api/run.ts +225 -0
  10. package/src/commands/auth-sessions/load.ts +42 -0
  11. package/src/commands/auth-sessions/run-check.ts +70 -0
  12. package/src/commands/auth-sessions/run-create.ts +124 -0
  13. package/src/commands/browser/save-state.ts +22 -0
  14. package/src/commands/browser/start-browser.ts +17 -0
  15. package/src/commands/build.ts +125 -0
  16. package/src/commands/common/browserUtils.ts +80 -0
  17. package/src/commands/common/getDefaultExportFromFile.ts +13 -0
  18. package/{dist/commands/common/getFirstLineNumber.test.js → src/commands/common/getFirstLineNumber.test.ts} +121 -75
  19. package/src/commands/common/getFirstLineNumber.ts +146 -0
  20. package/src/commands/common/sendMessageToClient.ts +8 -0
  21. package/src/commands/common/utils/fileUtils.ts +25 -0
  22. package/src/commands/common/utils/settings.ts +23 -0
  23. package/src/commands/common/utils/webTemplate.ts +46 -0
  24. package/src/commands/testing/saveVisibleHtml.ts +29 -0
  25. package/src/commands/ts-check.ts +88 -0
  26. package/src/common/Logger/Logger/index.ts +64 -0
  27. package/{dist/common/Logger/types.d.ts → src/common/Logger/Logger/types.ts} +5 -4
  28. package/src/common/Logger/index.ts +64 -0
  29. package/{dist/common/Logger/Logger/types.d.ts → src/common/Logger/types.ts} +5 -4
  30. package/src/common/asyncLocalStorage/index.ts +29 -0
  31. package/src/common/cleanEnvironmentVariables.ts +13 -0
  32. package/src/common/constants.ts +1 -0
  33. package/src/common/contextStorageStateHelpers.ts +71 -0
  34. package/src/common/getPlaywrightConstructs.ts +283 -0
  35. package/src/common/jwtTokenManager.ts +111 -0
  36. package/src/common/settingsSchema.ts +16 -0
  37. package/src/common/telemetry.ts +49 -0
  38. package/src/index.ts +14 -0
  39. package/src/runtime/RunError.ts +16 -0
  40. package/src/runtime/downloadDirectory.ts +14 -0
  41. package/src/runtime/enums.ts +11 -0
  42. package/src/runtime/executionHelpers.test.ts +70 -0
  43. package/src/runtime/extendPayload.ts +22 -0
  44. package/src/runtime/extendTimeout.ts +32 -0
  45. package/{dist/runtime/index.d.ts → src/runtime/index.ts} +3 -1
  46. package/src/runtime/requestMoreInfo.ts +40 -0
  47. package/src/runtime/runInfo.ts +19 -0
  48. package/vite.config.ts +17 -0
  49. package/bin/intuned-api-run +0 -2
  50. package/bin/intuned-auth-session-check +0 -2
  51. package/bin/intuned-auth-session-create +0 -2
  52. package/bin/intuned-auth-session-load +0 -2
  53. package/bin/intuned-auth-session-refresh +0 -2
  54. package/bin/intuned-browser-save-state +0 -2
  55. package/bin/intuned-browser-start +0 -2
  56. package/bin/intuned-build +0 -2
  57. package/bin/intuned-ts-check +0 -2
  58. package/dist/commands/api/run.d.ts +0 -6
  59. package/dist/commands/api/run.js +0 -135
  60. package/dist/commands/auth-sessions/load.d.ts +0 -2
  61. package/dist/commands/auth-sessions/load.js +0 -26
  62. package/dist/commands/auth-sessions/run-check.d.ts +0 -2
  63. package/dist/commands/auth-sessions/run-check.js +0 -42
  64. package/dist/commands/auth-sessions/run-create.d.ts +0 -2
  65. package/dist/commands/auth-sessions/run-create.js +0 -75
  66. package/dist/commands/browser/save-state.d.ts +0 -2
  67. package/dist/commands/browser/save-state.js +0 -17
  68. package/dist/commands/browser/start-browser.d.ts +0 -2
  69. package/dist/commands/browser/start-browser.js +0 -14
  70. package/dist/commands/build.d.ts +0 -2
  71. package/dist/commands/build.js +0 -80
  72. package/dist/commands/common/browserUtils.d.ts +0 -14
  73. package/dist/commands/common/browserUtils.js +0 -58
  74. package/dist/commands/common/getDefaultExportFromFile.d.ts +0 -1
  75. package/dist/commands/common/getDefaultExportFromFile.js +0 -19
  76. package/dist/commands/common/getFirstLineNumber.d.ts +0 -9
  77. package/dist/commands/common/getFirstLineNumber.js +0 -103
  78. package/dist/commands/common/sendMessageToClient.d.ts +0 -1
  79. package/dist/commands/common/sendMessageToClient.js +0 -10
  80. package/dist/commands/common/utils/fileUtils.d.ts +0 -6
  81. package/dist/commands/common/utils/fileUtils.js +0 -33
  82. package/dist/commands/common/utils/settings.d.ts +0 -2
  83. package/dist/commands/common/utils/settings.js +0 -28
  84. package/dist/commands/common/utils/webTemplate.d.ts +0 -1
  85. package/dist/commands/common/utils/webTemplate.js +0 -31
  86. package/dist/commands/ts-check.d.ts +0 -2
  87. package/dist/commands/ts-check.js +0 -54
  88. package/dist/common/Logger/Logger/index.d.ts +0 -12
  89. package/dist/common/Logger/Logger/index.js +0 -60
  90. package/dist/common/Logger/Logger/types.js +0 -5
  91. package/dist/common/Logger/index.d.ts +0 -12
  92. package/dist/common/Logger/index.js +0 -60
  93. package/dist/common/Logger/types.js +0 -5
  94. package/dist/common/asyncLocalStorage/index.d.ts +0 -16
  95. package/dist/common/asyncLocalStorage/index.js +0 -17
  96. package/dist/common/cleanEnvironmentVariables.d.ts +0 -1
  97. package/dist/common/cleanEnvironmentVariables.js +0 -16
  98. package/dist/common/constants.d.ts +0 -1
  99. package/dist/common/constants.js +0 -7
  100. package/dist/common/contextStorageStateHelpers.d.ts +0 -15
  101. package/dist/common/contextStorageStateHelpers.js +0 -48
  102. package/dist/common/getPlaywrightConstructs.d.ts +0 -28
  103. package/dist/common/getPlaywrightConstructs.js +0 -175
  104. package/dist/common/jwtTokenManager.d.ts +0 -16
  105. package/dist/common/jwtTokenManager.js +0 -81
  106. package/dist/common/settingsSchema.d.ts +0 -19
  107. package/dist/common/settingsSchema.js +0 -17
  108. package/dist/common/telemetry.d.ts +0 -3
  109. package/dist/common/telemetry.js +0 -32
  110. package/dist/index.d.ts +0 -4
  111. package/dist/index.js +0 -69
  112. package/dist/runtime/RunError.d.ts +0 -5
  113. package/dist/runtime/RunError.js +0 -19
  114. package/dist/runtime/downloadDirectory.d.ts +0 -1
  115. package/dist/runtime/downloadDirectory.js +0 -19
  116. package/dist/runtime/enums.d.js +0 -5
  117. package/dist/runtime/enums.js +0 -18
  118. package/dist/runtime/executionHelpers.test.js +0 -53
  119. package/dist/runtime/export.d.js +0 -5
  120. package/dist/runtime/extendPayload.d.ts +0 -2
  121. package/dist/runtime/extendPayload.js +0 -21
  122. package/dist/runtime/extendTimeout.d.ts +0 -1
  123. package/dist/runtime/extendTimeout.js +0 -26
  124. package/dist/runtime/index.js +0 -53
  125. package/dist/runtime/requestMoreInfo.d.ts +0 -17
  126. package/dist/runtime/requestMoreInfo.js +0 -25
  127. package/dist/runtime/runInfo.d.ts +0 -2
  128. package/dist/runtime/runInfo.js +0 -21
  129. /package/{dist → src}/common/assets/browser_scripts.js +0 -0
  130. /package/{dist → src}/runtime/enums.d.ts +0 -0
  131. /package/{dist → src}/runtime/export.d.ts +0 -0
@@ -0,0 +1,124 @@
1
+ #!/usr/bin/env node
2
+ import { Argument, program } from "commander";
3
+ import { getDefaultExportFromFile } from "../common/getDefaultExportFromFile";
4
+ import * as fs from "fs-extra";
5
+ import { saveSession } from "../common/browserUtils";
6
+ import { prompt } from "promptly";
7
+ import { getFullPathInProject } from "../common/utils/fileUtils";
8
+ import { getSettings } from "../common/utils/settings";
9
+ import dotenv from "dotenv";
10
+ import { AUTH_SESSIONS_FOLDER_NAME } from "../../common/constants";
11
+ import { getPlaywrightConstructsForMode } from "../../common/getPlaywrightConstructs";
12
+
13
+ dotenv.config({
14
+ path: `.env`,
15
+ });
16
+
17
+ program
18
+ .description("run auth session create")
19
+ .option("--cdpAddress <cdpAddress>", "CDP address", "http://localhost:9222")
20
+ .option("-i, --input [file]", "input json file")
21
+ .option("-j, --json [json]", "input json string")
22
+ .option(
23
+ "--authSessionPath <authSession>",
24
+ "auth session to use when executing the api"
25
+ )
26
+ .option(
27
+ "--pathToSave <pathToSave>",
28
+ "path to save the auth session, if not provided, will discard the auth session"
29
+ )
30
+ .allowUnknownOption()
31
+ .addArgument(
32
+ new Argument("<mode>", "mode of execution")
33
+ .choices(["vanilla", "playwright", "playwright-standalone"])
34
+ .default("playwright-standalone")
35
+ .argOptional()
36
+ )
37
+ .action(
38
+ async (
39
+ mode: "vanilla" | "playwright" | "playwright-standalone",
40
+ {
41
+ cdpAddress,
42
+ pathToSave,
43
+ input,
44
+ json,
45
+ }: {
46
+ cdpAddress: string;
47
+ pathToSave: string | undefined;
48
+ input: string;
49
+ json: string;
50
+ }
51
+ ) => {
52
+ let inputData: null | object = null;
53
+ if (input) {
54
+ inputData = await fs.readJSON(input);
55
+ } else if (json) {
56
+ inputData = JSON.parse(json);
57
+ } else {
58
+ inputData = {};
59
+ }
60
+
61
+ const setting = await getSettings();
62
+
63
+ if (!setting.authSessions.enabled) {
64
+ throw new Error("auth sessions feature is not enabled");
65
+ }
66
+
67
+ const createFilePath = getFullPathInProject(
68
+ AUTH_SESSIONS_FOLDER_NAME,
69
+ "create.ts"
70
+ );
71
+
72
+ if (!fs.exists(createFilePath)) {
73
+ throw new Error("auth session create file not found");
74
+ }
75
+
76
+ // Dynamically import the TypeScript file
77
+ const defaultExport = await getDefaultExportFromFile(createFilePath);
78
+ const { page, context } = await getPlaywrightConstructsForMode(
79
+ mode,
80
+ cdpAddress
81
+ );
82
+
83
+ const generator = await defaultExport(inputData, page, context, false);
84
+ let nextGeneratorParam: string | undefined = undefined;
85
+
86
+ // eslint-disable-next-line no-constant-condition
87
+ while (true) {
88
+ const { value, done } = await generator.next(nextGeneratorParam);
89
+
90
+ if (done) {
91
+ if (pathToSave) {
92
+ await saveSession(pathToSave, context);
93
+ }
94
+ break;
95
+ }
96
+
97
+ if (
98
+ value.action === "request_more_info" &&
99
+ value.requestType == "multiple_choice"
100
+ ) {
101
+ nextGeneratorParam = await prompt(
102
+ value.messageToUser + `, choices: ${value.choices}`,
103
+ {
104
+ validator: (input) => {
105
+ if (!value.choices.includes(input)) {
106
+ throw new Error("Please type on of the allowed choices");
107
+ }
108
+ return input;
109
+ },
110
+ }
111
+ );
112
+ } else if (
113
+ value.action === "request_more_info" &&
114
+ value.requestType == "otp"
115
+ ) {
116
+ nextGeneratorParam = await prompt(value.messageToUser, {});
117
+ }
118
+ }
119
+
120
+ process.exit(0);
121
+ }
122
+ );
123
+
124
+ program.parse(process.argv);
@@ -0,0 +1,22 @@
1
+ #!/usr/bin/env node
2
+ import { program } from "commander";
3
+ import { saveSessionFromOpenedBrowser } from "../common/browserUtils";
4
+ import dotenv from "dotenv";
5
+
6
+ dotenv.config({
7
+ path: `.env`,
8
+ });
9
+
10
+ program
11
+ .description("save browser state to file storage.json")
12
+ .option("-p, --path [file]", "path for file", "./localSessions/default.json")
13
+ .allowUnknownOption()
14
+ .action(async ({ path }) => {
15
+ await saveSessionFromOpenedBrowser(path);
16
+ // playwright keeps an open handle to the connected browser and it stops the process from exiting
17
+ // there is no way to close the connection gracefully without destroying the context/browser
18
+ // https://github.com/microsoft/playwright/issues/4956
19
+ process.exit(0);
20
+ });
21
+
22
+ program.parse(process.argv);
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env node
2
+ import { program } from "commander";
3
+ import { startOrRestartBrowser } from "../common/browserUtils";
4
+ import dotenv from "dotenv";
5
+
6
+ dotenv.config({
7
+ path: `.env`,
8
+ });
9
+
10
+ program
11
+ .description("start browser testing purposes")
12
+ .allowUnknownOption()
13
+ .action(async () => {
14
+ await startOrRestartBrowser();
15
+ });
16
+
17
+ program.parse(process.argv);
@@ -0,0 +1,125 @@
1
+ #!/usr/bin/env node
2
+ import { program, Argument } from "commander";
3
+ import { RollupBuild, RollupLog, rollup } from "rollup";
4
+ import typescript from "@rollup/plugin-typescript";
5
+ import commonjs from "@rollup/plugin-commonjs";
6
+ import { nodeResolve } from "@rollup/plugin-node-resolve";
7
+ import dynamicImportVars from "@rollup/plugin-dynamic-import-vars";
8
+ import json from "@rollup/plugin-json";
9
+ import * as fs from "fs-extra";
10
+ import * as path from "path";
11
+ import { moveWebTemplateFiles } from "./common/utils/webTemplate";
12
+
13
+ function isThirdPartyWarning(warning: RollupLog) {
14
+ if (warning.id && /node_modules/.test(warning.id)) return true;
15
+ if (warning.ids && warning.ids.every((id) => /node_modules/.test(id)))
16
+ return true;
17
+
18
+ return false;
19
+ }
20
+
21
+ import dotenv from "dotenv";
22
+ dotenv.config();
23
+
24
+ program
25
+ .description("build the intuned server")
26
+ .addArgument(
27
+ new Argument("<mode>", "mode of execution")
28
+ .choices(["vanilla", "playwright"])
29
+ .default("playwright")
30
+ .argOptional()
31
+ )
32
+ .argument("[outfile]", "output bundle", "./output/bundle_v2.js")
33
+ .allowUnknownOption()
34
+ .action(async (mode, outfile) => {
35
+ await moveWebTemplateFiles();
36
+
37
+ const currentTemplateTsConfig = path.resolve(
38
+ __dirname,
39
+ "..",
40
+ "..",
41
+ "template.tsconfig.json"
42
+ );
43
+ await fs.copy(
44
+ currentTemplateTsConfig,
45
+ "./intuned/WebTemplate/tsconfig.json"
46
+ );
47
+
48
+ await build(outfile, mode);
49
+ });
50
+
51
+ async function build(outfile: string, mode: "playwright" | "vanilla") {
52
+ let bundle: RollupBuild | null = null;
53
+ let buildFailed = false;
54
+
55
+ try {
56
+ // create a bundle
57
+ bundle = await rollup({
58
+ input: `./intuned/WebTemplate/index.${mode}.ts`,
59
+ output: {
60
+ globals: { crypto: "crypto" },
61
+ },
62
+ plugins: [
63
+ json(),
64
+ nodeResolve({ exportConditions: ["node"], preferBuiltins: true }),
65
+ typescript({ tsconfig: "./intuned/WebTemplate/tsconfig.json" }),
66
+ commonjs({
67
+ include: [
68
+ "node_modules/**",
69
+ "intuned/WebTemplate/**",
70
+ "dist",
71
+ "../runner/**",
72
+ ],
73
+ extensions: [".js"],
74
+ ignoreGlobal: false,
75
+ sourceMap: false,
76
+ }),
77
+ dynamicImportVars({
78
+ include: ["**/*.js", "**/*.ts"],
79
+ exclude: ["**/*.d.ts", "**/*.js.map"],
80
+ }),
81
+ ],
82
+ onwarn: (warning, warn) => {
83
+ if (isThirdPartyWarning(warning)) return;
84
+ warn(warning);
85
+ },
86
+ external: [
87
+ "@intuned/playwright",
88
+ "@intuned/playwright-core",
89
+ "jsdom",
90
+ "canvas",
91
+ "pdfjs-dist",
92
+ "pdf-to-png-converter",
93
+ "crypto",
94
+ "applicationinsights",
95
+ "fingerprint-generator",
96
+ "fingerprint-injector",
97
+ ],
98
+ });
99
+
100
+ console.log(`📦 Building ${outfile}`);
101
+ const outfileFolder = path.dirname(outfile);
102
+
103
+ // copy assets to outfile folder
104
+ const assetsDir = path.resolve(__dirname, "..", "common", "assets");
105
+ await fs.copy(assetsDir, `${outfileFolder}/assets`);
106
+
107
+ await bundle.write({
108
+ format: "cjs",
109
+ file: outfile,
110
+ inlineDynamicImports: true,
111
+ });
112
+
113
+ console.log(`✨ Build succeeded: ${outfile}`);
114
+ } catch (error) {
115
+ buildFailed = true;
116
+ console.error("error", error);
117
+ }
118
+
119
+ if (buildFailed) {
120
+ console.error("build failed");
121
+ process.exit(1);
122
+ }
123
+ }
124
+
125
+ program.parse(process.argv);
@@ -0,0 +1,80 @@
1
+ // this file is to make testing easier only.
2
+
3
+ import { spawn } from "child_process";
4
+ import * as playwright from "@intuned/playwright-core";
5
+ import * as fs from "fs-extra";
6
+ import { BrowserContext } from "@intuned/playwright-core";
7
+ import { getFullPathInProject } from "./utils/fileUtils";
8
+ import { getContextStorageState } from "../../common/contextStorageStateHelpers";
9
+
10
+ export const REMOTE_DEBUGGING_PORT = 9222;
11
+
12
+ export const getChromiumLaunchArgs = () => [
13
+ "--no-sandbox",
14
+ `--remote-debugging-port=${REMOTE_DEBUGGING_PORT}`,
15
+ `--user-data-dir=/tmp/${Date.now()}`,
16
+ "--new-window",
17
+ "--start-maximized",
18
+ "--disable-popup-blocking",
19
+ ];
20
+
21
+ // this is needed cause we need to keep the same browser instance alive between start recording and stop recording calls.
22
+ async function getBrowser() {
23
+ let playwrightBrowser: playwright.Browser | null = null;
24
+
25
+ try {
26
+ playwrightBrowser = await playwright.chromium.connectOverCDP(
27
+ `http://localhost:${REMOTE_DEBUGGING_PORT}`
28
+ );
29
+ } catch (e) {
30
+ throw new Error("Browser is not running");
31
+ }
32
+
33
+ return playwrightBrowser;
34
+ }
35
+
36
+ export async function startOrRestartBrowser() {
37
+ const chromiumPath = await playwright.chromium.executablePath();
38
+
39
+ const chromeInstanceProcess = spawn(chromiumPath, getChromiumLaunchArgs());
40
+
41
+ chromeInstanceProcess.stdout.on("data", (data) => {
42
+ console.log(`Chrome stdout: ${data}`);
43
+ });
44
+
45
+ chromeInstanceProcess.stderr.on("data", (data) => {
46
+ console.error(`Chrome stderr: ${data}`);
47
+ });
48
+ }
49
+
50
+ export interface SessionState {
51
+ cookies: any[];
52
+ storage: Record<string, { localStorage: any; sessionStorage: any }>;
53
+ }
54
+
55
+ export async function saveSessionFromOpenedBrowser(path: string) {
56
+ const browser = await getBrowser();
57
+ const context = await browser.contexts()[0];
58
+
59
+ return saveSession(path, context);
60
+ }
61
+
62
+ export async function loadState(path: string, context: BrowserContext) {
63
+ const fullPath = getFullPathInProject(path);
64
+ if (!(await fs.pathExists(fullPath))) {
65
+ throw new Error("session file does not exist");
66
+ }
67
+
68
+ const data: SessionState = await fs.readJson(fullPath);
69
+
70
+ await context.addCookies(data.cookies);
71
+
72
+ // ToDo: logic to load storage without using the page.
73
+ }
74
+
75
+ export async function saveSession(path: string, context: BrowserContext) {
76
+ const fullState = await getContextStorageState(context);
77
+ const fullPath = getFullPathInProject(path);
78
+ fs.ensureFileSync(fullPath);
79
+ await fs.writeJSON(fullPath, fullState);
80
+ }
@@ -0,0 +1,13 @@
1
+ export async function getDefaultExportFromFile(apiFilePath: string) {
2
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
3
+ require("ts-node").register({
4
+ transpileOnly: true,
5
+ compilerOptions: {
6
+ lib: ["dom", "es2020"],
7
+ },
8
+ });
9
+
10
+ const imported = await import(apiFilePath);
11
+ const defaultExport = imported.default;
12
+ return defaultExport;
13
+ }
@@ -1,30 +1,33 @@
1
- "use strict";
2
-
3
- var _vitest = require("vitest");
4
- var _getFirstLineNumber = _interopRequireDefault(require("./getFirstLineNumber"));
5
- var fs = _interopRequireWildcard(require("fs"));
6
- var path = _interopRequireWildcard(require("path"));
7
- function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
8
- function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
9
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
10
- (0, _vitest.describe)("getFirstLineNumber", () => {
1
+ import { expect, describe, it, beforeAll, afterAll } from "vitest";
2
+ import getFirstLineNumber from "./getFirstLineNumber";
3
+ import * as fs from "fs";
4
+ import * as path from "path";
5
+
6
+ describe("getFirstLineNumber", () => {
11
7
  const testFilesDir = path.join(__dirname, "testFiles");
12
- const createTestFile = (fileName, content) => {
8
+ const createTestFile = (fileName: string, content: string) => {
13
9
  const filePath = path.join(testFilesDir, fileName);
14
10
  fs.writeFileSync(filePath, content);
15
11
  return filePath;
16
12
  };
17
- (0, _vitest.beforeAll)(() => {
13
+
14
+ beforeAll(() => {
18
15
  if (!fs.existsSync(testFilesDir)) {
19
16
  fs.mkdirSync(testFilesDir);
20
17
  }
21
18
  });
22
- (0, _vitest.afterAll)(() => {
23
- fs.readdirSync(testFilesDir).forEach(file => fs.unlinkSync(path.join(testFilesDir, file)));
19
+
20
+ afterAll(() => {
21
+ fs.readdirSync(testFilesDir).forEach((file) =>
22
+ fs.unlinkSync(path.join(testFilesDir, file))
23
+ );
24
24
  fs.rmdirSync(testFilesDir);
25
25
  });
26
- (0, _vitest.it)("correctly identifies first line in a default exported named function", async () => {
27
- const filePath = createTestFile("defaultFunction.ts", `import {
26
+
27
+ it("correctly identifies first line in a default exported named function", async () => {
28
+ const filePath = createTestFile(
29
+ "defaultFunction.ts",
30
+ `import {
28
31
  EnhancedPlaywrightPage,
29
32
  EnhancedPlaywrightBrowserContext,
30
33
  ExecutionHelpers,
@@ -45,12 +48,16 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
45
48
  await page.getByLabel("Search Wikipedia").press("Enter");
46
49
  return { done: "true", name: "custom name from api1" };
47
50
  }
48
- `);
49
- const result = await (0, _getFirstLineNumber.default)(filePath);
50
- (0, _vitest.expect)(result.lineNumber).toBe(4);
51
+ `
52
+ );
53
+ const result = await getFirstLineNumber(filePath);
54
+ expect(result.lineNumber).toBe(4); // 4 is the index after it's compiled to commonjs
51
55
  });
52
- (0, _vitest.it)("correctly identifies first line in a default exported anonymous function", async () => {
53
- const filePath = createTestFile("defaultFunction.ts", `import {
56
+
57
+ it("correctly identifies first line in a default exported anonymous function", async () => {
58
+ const filePath = createTestFile(
59
+ "defaultFunction.ts",
60
+ `import {
54
61
  EnhancedPlaywrightPage,
55
62
  EnhancedPlaywrightBrowserContext,
56
63
  ExecutionHelpers,
@@ -71,12 +78,16 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
71
78
  await page.getByLabel("Search Wikipedia").press("Enter");
72
79
  return { done: "true", name: "custom name from api1" };
73
80
  }
74
- `);
75
- const result = await (0, _getFirstLineNumber.default)(filePath);
76
- (0, _vitest.expect)(result.lineNumber).toBe(4);
81
+ `
82
+ );
83
+ const result = await getFirstLineNumber(filePath);
84
+ expect(result.lineNumber).toBe(4);
77
85
  });
78
- (0, _vitest.it)("correctly identifies first line in a default exported function identifier", async () => {
79
- const filePath = createTestFile("defaultFunction.ts", `import {
86
+
87
+ it("correctly identifies first line in a default exported function identifier", async () => {
88
+ const filePath = createTestFile(
89
+ "defaultFunction.ts",
90
+ `import {
80
91
  EnhancedPlaywrightPage,
81
92
  EnhancedPlaywrightBrowserContext,
82
93
  ExecutionHelpers,
@@ -98,12 +109,16 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
98
109
  return { done: "true", name: "custom name from api1" };
99
110
  }
100
111
  export default runApi;
101
- `);
102
- const result = await (0, _getFirstLineNumber.default)(filePath);
103
- (0, _vitest.expect)(result.lineNumber).toBe(4);
112
+ `
113
+ );
114
+ const result = await getFirstLineNumber(filePath);
115
+ expect(result.lineNumber).toBe(4);
104
116
  });
105
- (0, _vitest.it)("correctly identifies first line in a file with multiple exports including a default function", async () => {
106
- const filePath = createTestFile("multipleExports.ts", `import {
117
+
118
+ it("correctly identifies first line in a file with multiple exports including a default function", async () => {
119
+ const filePath = createTestFile(
120
+ "multipleExports.ts",
121
+ `import {
107
122
  EnhancedPlaywrightPage,
108
123
  EnhancedPlaywrightBrowserContext,
109
124
  ExecutionHelpers,
@@ -125,12 +140,16 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
125
140
  await page.getByLabel("Search Wikipedia").press("Enter");
126
141
  return { done: "true", name: "custom name from api1" };
127
142
  }
128
- export default runApi;`);
129
- const result = await (0, _getFirstLineNumber.default)(filePath);
130
- (0, _vitest.expect)(result.lineNumber).toBe(7);
143
+ export default runApi;`
144
+ );
145
+ const result = await getFirstLineNumber(filePath);
146
+ expect(result.lineNumber).toBe(7);
131
147
  });
132
- (0, _vitest.it)("correctly identifies first line in a default exported arrow function identifier", async () => {
133
- const filePath = createTestFile("multipleExports.ts", `import {
148
+
149
+ it("correctly identifies first line in a default exported arrow function identifier", async () => {
150
+ const filePath = createTestFile(
151
+ "multipleExports.ts",
152
+ `import {
134
153
  EnhancedPlaywrightPage,
135
154
  EnhancedPlaywrightBrowserContext,
136
155
  ExecutionHelpers,
@@ -151,12 +170,16 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
151
170
  await page.getByLabel("Search Wikipedia").press("Enter");
152
171
  return { done: "true", name: "custom name from api1" };
153
172
  }
154
- export default runApi;`);
155
- const result = await (0, _getFirstLineNumber.default)(filePath);
156
- (0, _vitest.expect)(result.lineNumber).toBe(4);
173
+ export default runApi;`
174
+ );
175
+ const result = await getFirstLineNumber(filePath);
176
+ expect(result.lineNumber).toBe(4);
157
177
  });
158
- (0, _vitest.it)("correctly identifies first line in a default exported anonymous arrow function", async () => {
159
- const filePath = createTestFile("multipleExports.ts", `import {
178
+
179
+ it("correctly identifies first line in a default exported anonymous arrow function", async () => {
180
+ const filePath = createTestFile(
181
+ "multipleExports.ts",
182
+ `import {
160
183
  EnhancedPlaywrightPage,
161
184
  EnhancedPlaywrightBrowserContext,
162
185
  ExecutionHelpers,
@@ -176,53 +199,76 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
176
199
  await page.getByLabel("Search Wikipedia").type(params.name);
177
200
  await page.getByLabel("Search Wikipedia").press("Enter");
178
201
  return { done: "true", name: "custom name from api1" };
179
- };`);
180
- const result = await (0, _getFirstLineNumber.default)(filePath);
181
- (0, _vitest.expect)(result.lineNumber).toBe(4);
202
+ };`
203
+ );
204
+ const result = await getFirstLineNumber(filePath);
205
+ expect(result.lineNumber).toBe(4);
182
206
  });
183
- (0, _vitest.it)("identifies first executable line in a default exported arrow function", async () => {
184
- const filePath = createTestFile("defaultArrowFunction.ts", `export default () => {
207
+
208
+ it("identifies first executable line in a default exported arrow function", async () => {
209
+ const filePath = createTestFile(
210
+ "defaultArrowFunction.ts",
211
+ `export default () => {
185
212
  console.log("Hello, Arrow World!");
186
- };`);
187
- const result = await (0, _getFirstLineNumber.default)(filePath);
188
- (0, _vitest.expect)(result.lineNumber).toBe(4);
213
+ };`
214
+ );
215
+ const result = await getFirstLineNumber(filePath);
216
+ expect(result.lineNumber).toBe(4);
189
217
  });
190
- (0, _vitest.it)("identifies first executable line within nested functions of a default export", async () => {
191
- const filePath = createTestFile("nestedFunctions.ts", `const x = 4;
218
+
219
+ it("identifies first executable line within nested functions of a default export", async () => {
220
+ const filePath = createTestFile(
221
+ "nestedFunctions.ts",
222
+ `const x = 4;
192
223
  export default function() {
193
224
  const nested = (x) => console.log("Nested function call");
194
225
  nested(x);
195
- }`);
196
- const result = await (0, _getFirstLineNumber.default)(filePath);
197
- (0, _vitest.expect)(result.lineNumber).toBe(5);
226
+ }`
227
+ );
228
+ const result = await getFirstLineNumber(filePath);
229
+ expect(result.lineNumber).toBe(5);
198
230
  });
199
- (0, _vitest.it)("handles async default exported function correctly", async () => {
200
- const filePath = createTestFile("asyncDefaultFunction.ts", `export default async function() {
231
+
232
+ it("handles async default exported function correctly", async () => {
233
+ const filePath = createTestFile(
234
+ "asyncDefaultFunction.ts",
235
+ `export default async function() {
201
236
  await Promise.resolve(console.log("Async Hello, World!"));
202
- }`);
203
- const result = await (0, _getFirstLineNumber.default)(filePath);
204
- (0, _vitest.expect)(result.lineNumber).toBe(4);
237
+ }`
238
+ );
239
+ const result = await getFirstLineNumber(filePath);
240
+ expect(result.lineNumber).toBe(4);
205
241
  });
206
- (0, _vitest.it)("returns -1 for a default exported class", async () => {
207
- const filePath = createTestFile("defaultClass.ts", `export default class MyClass {
242
+
243
+ it("returns -1 for a default exported class", async () => {
244
+ const filePath = createTestFile(
245
+ "defaultClass.ts",
246
+ `export default class MyClass {
208
247
  constructor() {}
209
- }`);
210
- const result = await (0, _getFirstLineNumber.default)(filePath);
211
- (0, _vitest.expect)(result.lineNumber).toBe(-1);
248
+ }`
249
+ );
250
+ const result = await getFirstLineNumber(filePath);
251
+ expect(result.lineNumber).toBe(-1);
212
252
  });
213
- (0, _vitest.it)("returns -1 for a default exported variable", async () => {
253
+
254
+ it("returns -1 for a default exported variable", async () => {
214
255
  const filePath = createTestFile("defaultVariable.ts", `export default 42;`);
215
- const result = await (0, _getFirstLineNumber.default)(filePath);
216
- (0, _vitest.expect)(result.lineNumber).toBe(-1);
256
+ const result = await getFirstLineNumber(filePath);
257
+ expect(result.lineNumber).toBe(-1);
217
258
  });
218
- (0, _vitest.it)("returns -1 when there is no default export", async () => {
219
- const filePath = createTestFile("noDefaultExport.ts", `export const foo = () => console.log("bar");`);
220
- const result = await (0, _getFirstLineNumber.default)(filePath);
221
- (0, _vitest.expect)(result.lineNumber).toBe(-1);
259
+
260
+ it("returns -1 when there is no default export", async () => {
261
+ const filePath = createTestFile(
262
+ "noDefaultExport.ts",
263
+ `export const foo = () => console.log("bar");`
264
+ );
265
+ const result = await getFirstLineNumber(filePath);
266
+ expect(result.lineNumber).toBe(-1);
222
267
  });
223
- (0, _vitest.it)("returns -1 for an empty file", async () => {
268
+
269
+ it("returns -1 for an empty file", async () => {
224
270
  const filePath = createTestFile("emptyFile.ts", ``);
225
- const result = await (0, _getFirstLineNumber.default)(filePath);
226
- (0, _vitest.expect)(result.lineNumber).toBe(-1);
271
+ const result = await getFirstLineNumber(filePath);
272
+ expect(result.lineNumber).toBe(-1);
227
273
  });
228
- });
274
+ });