@rpcbase/test 0.120.0 → 0.122.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/package.json CHANGED
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "name": "@rpcbase/test",
3
- "version": "0.120.0",
3
+ "version": "0.122.0",
4
+ "type": "module",
4
5
  "bin": {
5
6
  "rb-test": "./src/cli.js"
6
7
  },
@@ -32,8 +33,9 @@
32
33
  }
33
34
  },
34
35
  "dependencies": {
35
- "@playwright/test": "1.52.0",
36
- "lodash": "4.17.21"
36
+ "@playwright/test": "1.53.1",
37
+ "lodash": "4.17.21",
38
+ "mongoose": "8.16.1"
37
39
  },
38
40
  "devDependencies": {}
39
41
  }
@@ -0,0 +1,19 @@
1
+ import mongoose from "mongoose"
2
+
3
+
4
+ export async function clearDatabase(dbName) {
5
+ const { MONGO_PORT, APP_NAME } = process.env
6
+
7
+ const connectionString = `mongodb://localhost:${MONGO_PORT}/${APP_NAME}-${dbName}`
8
+
9
+ console.log("will clear DB:", connectionString)
10
+
11
+ const connection = await mongoose
12
+ .createConnection(connectionString)
13
+ .asPromise()
14
+
15
+ // Drop the database
16
+ await connection.dropDatabase()
17
+
18
+ await connection.close()
19
+ }
package/src/cli.js CHANGED
@@ -1,12 +1,14 @@
1
1
  #!/usr/bin/env node
2
- const { spawn } = require("child_process");
3
- const fs = require("fs");
4
- const path = require("path");
5
2
 
6
- const isAider = process.env.IS_AIDER === "yes";
3
+ import { spawn } from "child_process"
4
+ import fs from "fs"
5
+ import path from "path"
6
+
7
+
8
+ const isAider = process.env.IS_AIDER === "yes"
7
9
 
8
10
  if (process.env.IS_AIDER !== undefined && process.env.IS_AIDER !== "yes") {
9
- console.warn("Warning: IS_AIDER is set to a value other than 'yes'.");
11
+ console.warn("Warning: IS_AIDER is set to a value other than 'yes'.")
10
12
  }
11
13
 
12
14
  function runTests() {
@@ -16,10 +18,10 @@ function runTests() {
16
18
  path.join(process.cwd(), "playwright.config.ts"),
17
19
  )
18
20
  ? path.join(process.cwd(), "playwright.config.ts")
19
- : path.join(__dirname, "playwright.config.ts");
21
+ : path.join(__dirname, "playwright.config.ts")
20
22
 
21
- const stdoutBuffer = [];
22
- const stderrBuffer = [];
23
+ const stdoutBuffer = []
24
+ const stderrBuffer = []
23
25
 
24
26
  const playwright = spawn(
25
27
  "./node_modules/.bin/playwright",
@@ -27,37 +29,41 @@ function runTests() {
27
29
  {
28
30
  shell: false,
29
31
  },
30
- );
32
+ )
31
33
 
32
34
  playwright.stdout.on("data", (data) => {
33
- !isAider && process.stdout.write(data);
34
- stdoutBuffer.push(data.toString());
35
- });
35
+ if (!isAider) {
36
+ process.stdout.write(data)
37
+ }
38
+ stdoutBuffer.push(data.toString())
39
+ })
36
40
 
37
41
  playwright.stderr.on("data", (data) => {
38
- !isAider && process.stderr.write(data);
39
- stderrBuffer.push(data.toString());
40
- });
42
+ if (!isAider) {
43
+ process.stderr.write(data)
44
+ }
45
+ stderrBuffer.push(data.toString())
46
+ })
41
47
 
42
48
  playwright.on("close", (code) => {
43
49
  if (code === 0) {
44
- console.log("All tests passed!");
45
- resolve();
50
+ console.log("All tests passed!")
51
+ resolve()
46
52
  } else {
47
- console.error("Tests failed:");
53
+ console.error("Tests failed:")
48
54
  console.error(stdoutBuffer.join(""))
49
55
 
50
- reject(new Error(`Tests failed with exit code: ${code}`));
56
+ reject(new Error(`Tests failed with exit code: ${code}`))
51
57
  }
52
- });
58
+ })
53
59
 
54
60
  playwright.on("error", (error) => {
55
- console.error("Error spawning Playwright:", error);
56
- reject(error);
57
- });
58
- });
61
+ console.error("Error spawning Playwright:", error)
62
+ reject(error)
63
+ })
64
+ })
59
65
  }
60
66
 
61
67
  runTests()
62
68
  .then(() => process.exit(0))
63
- .catch(() => process.exit(1));
69
+ .catch(() => process.exit(1))
@@ -1,11 +1,12 @@
1
- const fs = require("fs")
2
- const {cpus} = require("os")
3
- const _merge = require("lodash/merge")
4
- const {defineConfig, devices} = require("@playwright/test")
1
+ import fs from "fs"
2
+ import { cpus } from "os"
3
+
4
+ import _ from "lodash"
5
+ import { defineConfig, devices } from "@playwright/test"
5
6
 
6
7
 
7
8
  function mergeConfig(base, override) {
8
- return _merge({}, base, override);
9
+ return _.merge({}, base, override)
9
10
  }
10
11
 
11
12
  const hasPassedAllPreviousTests = (data) => {
@@ -65,8 +66,8 @@ const isHeadless = () => {
65
66
  }
66
67
 
67
68
 
68
- // https://playwright.dev/docs/test-configuration.
69
- module.exports = function(config) {
69
+ // https://playwright.dev/docs/test-configuration
70
+ export default function(config) {
70
71
 
71
72
  const baseConfig = {
72
73
  globalSetup: ["./spec/helpers/globalSetup.ts"],
package/src/index.js CHANGED
@@ -1,3 +1,2 @@
1
- const defineConfig = require("./defineConfig")
2
-
3
- module.exports = {defineConfig}
1
+ // export * from "./defineConfig"
2
+ export * from "./clearDatabase"