@digigov/cli-test 2.0.0-rc.20 → 2.0.0-rc.22

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.
@@ -1,15 +1,10 @@
1
1
  {
2
- "../../tooling/cli-test": "../../tooling/cli-test:0pLPlpkhBLZn+8ae/eUwnKrziLGttU8eN8S5BLx7PBE=:",
3
- "/@testing-library/jest-dom@6.1.4(@jest/globals@29.7.0)(@types/jest@29.0.2)(jest@29.0.2(@types/node@18.19.0)(babel-plugin-macros@3.1.0)(node-notifier@8.0.2)(ts-node@10.9.2(@types/node@18.19.0)(typescript@5.6.2)))": "Missing shrinkwrap entry!",
4
- "/@testing-library/react@15.0.7(@types/react@18.3.3)(react-dom@18.3.1(react@18.3.1))(react@18.3.1)": "Missing shrinkwrap entry!",
5
- "/@types/jest@29.0.2": "Missing shrinkwrap entry!",
6
- "/@types/node@18.19.0": "Missing shrinkwrap entry!",
7
- "/@types/react@18.3.3": "Missing shrinkwrap entry!",
8
- "/babel-jest@29.0.2(@babel/core@7.12.13)": "Missing shrinkwrap entry!",
9
- "/babel-plugin-istanbul@7.0.0": "Missing shrinkwrap entry!",
10
- "/jest-cli@29.0.2(@types/node@18.19.0)(babel-plugin-macros@3.1.0)(node-notifier@8.0.2)(ts-node@10.9.2(@types/node@18.19.0)(typescript@5.6.2))": "Missing shrinkwrap entry!",
11
- "/jest-environment-jsdom@29.0.2": "Missing shrinkwrap entry!",
12
- "/jest@29.0.2(@types/node@18.19.0)(babel-plugin-macros@3.1.0)(node-notifier@8.0.2)(ts-node@10.9.2(@types/node@18.19.0)(typescript@5.6.2))": "Missing shrinkwrap entry!",
2
+ "../../tooling/cli-test": "../../tooling/cli-test:pMkmz3EGXjjxFWyjvMi7eIIHnaSWxUUhI5JxCg+bIj0=:",
3
+ "/@testing-library/dom@10.4.0": "Missing shrinkwrap entry!",
4
+ "/@testing-library/jest-dom@6.1.4(@jest/globals@29.7.0)(@types/jest@29.0.2)(jest@29.0.2(@types/node@22.7.5)(babel-plugin-macros@3.1.0)(node-notifier@8.0.2))(vitest@2.1.3(@types/node@22.7.5)(happy-dom@15.11.0)(jsdom@20.0.3)(lightningcss@1.22.0)(sass-embedded@1.81.0)(terser@5.33.0))": "Missing shrinkwrap entry!",
5
+ "/@testing-library/react@16.0.1(@testing-library/dom@10.4.0)(@types/react-dom@18.3.0)(@types/react@18.3.3)(react-dom@18.3.1(react@18.3.1))(react@18.3.1)": "Missing shrinkwrap entry!",
6
+ "/@vitest/coverage-istanbul@2.1.3(vitest@2.1.3(@types/node@22.7.5)(happy-dom@15.11.0)(jsdom@20.0.3)(lightningcss@1.22.0)(sass-embedded@1.81.0)(terser@5.33.0))": "Missing shrinkwrap entry!",
13
7
  "/publint@0.1.8": "Missing shrinkwrap entry!",
14
- "/typescript@5.6.2": "Missing shrinkwrap entry!"
8
+ "/vite-tsconfig-paths@5.0.1(typescript@5.6.2)(vite@5.4.11(@types/node@22.7.5)(lightningcss@1.22.0)(sass-embedded@1.81.0)(terser@5.33.0))": "Missing shrinkwrap entry!",
9
+ "/vitest@2.1.3(@types/node@22.7.5)(happy-dom@15.11.0)(jsdom@20.0.3)(lightningcss@1.22.0)(sass-embedded@1.81.0)(terser@5.33.0)": "Missing shrinkwrap entry!"
15
10
  }
package/dirsum.js CHANGED
@@ -1,72 +1,84 @@
1
- const crypto = require('crypto');
2
- const fs = require('fs');
1
+ import crypto from "crypto";
2
+ import fs from "fs";
3
3
 
4
- function _summarize(method, hashes) {
5
- const keys = Object.keys(hashes);
6
- keys.sort();
7
-
8
- const obj = {};
9
- obj.files = hashes;
10
- const hash = crypto.createHash(method);
11
- for(let i = 0; i < keys.length; i++) {
12
- if(typeof (hashes[keys[i]]) === 'string') {
13
- hash.update(hashes[keys[i]]);
14
- } else if(typeof (hashes[keys[i]]) === 'object') {
15
- hash.update(hashes[keys[i]].hash);
16
- } else {
17
- console.error('Unknown type found in hash: ' + typeof (hashes[keys[i]]));
18
- }
19
- }
20
-
21
- obj.hash = hash.digest('hex');
22
- return obj;
23
- }
4
+ const method = "sha1";
24
5
 
25
- const method = 'sha1';
26
- function digest(root, options) {
27
- if(!root || typeof (root) !== 'string') {
28
- throw new TypeError('root is required (string)');
6
+ /**
7
+ * Generate a digest of a directory
8
+ *
9
+ * @param {string} root - The root directory
10
+ * @param {object} options - The options
11
+ * @param {RegExp|string} options.ignore - The ignore pattern
12
+ */
13
+ export function digest(root, options) {
14
+ if (!root || typeof root !== "string") {
15
+ throw new TypeError("root is required (string)");
29
16
  }
30
- if(options.ignore){
31
- if(root.match(options.ignore)){
32
- return {hash: '', files: {}};
17
+ if (options.ignore) {
18
+ if (root.match(options.ignore)) {
19
+ return { hash: "", files: {} };
33
20
  }
34
21
  }
35
22
  const hashes = {};
36
23
  const files = fs.readdirSync(root);
37
- if(files.length === 0) {
38
- return {hash: '', files: {}};
24
+ if (files.length === 0) {
25
+ return { hash: "", files: {} };
39
26
  }
40
27
 
41
28
  let hashed = 0;
42
- for(const f of files) {
43
- const path = root + '/' + f;
29
+ for (const f of files) {
30
+ const path = root + "/" + f;
44
31
  const stats = fs.statSync(path);
45
32
 
46
- if(stats.isDirectory()) {
33
+ if (stats.isDirectory()) {
47
34
  const hash = digest(path, options);
48
35
  hashes[f] = hash;
49
- if(++hashed >= files.length) {
36
+ if (++hashed >= files.length) {
50
37
  return _summarize(method, hashes);
51
38
  }
52
- } else if(stats.isFile()) {
53
- const data = fs.readFileSync(path, 'utf8');
39
+ } else if (stats.isFile()) {
40
+ const data = fs.readFileSync(path, "utf8");
54
41
 
55
42
  const hash = crypto.createHash(method);
56
43
  hash.update(data);
57
- hashes[f] = hash.digest('hex');
44
+ hashes[f] = hash.digest("hex");
58
45
 
59
- if(++hashed >= files.length) {
46
+ if (++hashed >= files.length) {
60
47
  return _summarize(method, hashes);
61
48
  }
62
49
  } else {
63
- console.error('Skipping hash of %s', f);
64
- if(++hashed > files.length) {
50
+ console.error("Skipping hash of %s", f);
51
+ if (++hashed > files.length) {
65
52
  return _summarize(method, hashes);
66
53
  }
67
54
  }
68
55
  }
56
+ return { hash: "", files: {} };
57
+ }
58
+
59
+ /**
60
+ * @param {string} method - The method
61
+ * @param {Hashes} hashes - The hashes
62
+ */
63
+ function _summarize(method, hashes) {
64
+ const keys = Object.keys(hashes);
65
+ keys.sort();
66
+
67
+ const obj = {
68
+ files: hashes,
69
+ hash: "",
70
+ };
71
+ const hash = crypto.createHash(method);
72
+ for (const key of keys) {
73
+ if (typeof hashes[key] === "string") {
74
+ hash.update(hashes[key]);
75
+ } else if (typeof hashes[key] === "object") {
76
+ hash.update(hashes[key]["hash"]);
77
+ } else {
78
+ console.error("Unknown type found in hash: " + typeof hashes[key]);
79
+ }
80
+ }
81
+
82
+ obj["hash"] = hash.digest("hex");
83
+ return obj;
69
84
  }
70
- module.exports = {
71
- digest: digest
72
- };
package/index.js CHANGED
@@ -1,23 +1,26 @@
1
- const execa = require('execa')
2
- const path = require('path')
3
- const {DigigovCommand} = require('@digigov/cli/lib')
1
+ import path from "path";
2
+ import { DigigovCommand } from "@digigov/cli/lib";
3
+ import { fileURLToPath } from "url";
4
4
 
5
- module.exports = class Test extends DigigovCommand {
6
- static description = 'test digigov projects'
7
- static id = 'test'
8
- dirname=__dirname
9
- static examples = [
10
- `$ digigov test`,
11
- ]
5
+ const command = new DigigovCommand("test", import.meta.url);
12
6
 
13
- static load() { return Test }
14
- script = 'jest'
15
- async run() {
16
- const proc = this.exec(this.script, [
17
- '--config',
18
- path.join(__dirname, 'jest.config.js'),
19
- ...this.argv
20
- ], { env: {}, stdio: 'inherit' });
21
- return proc;
22
- }
7
+ command
8
+ .argument("[args...]", "arguments to pass to test runner")
9
+ .helpOption(false)
10
+ .allowUnknownOption()
11
+ .action(runTest);
12
+
13
+ export default command;
14
+
15
+ /**
16
+ * @param {string[]} args - The arguments
17
+ * @param {DigigovCommand} ctx - The command context
18
+ */
19
+ async function runTest(args, _, ctx) {
20
+ const __dirname = path.dirname(fileURLToPath(import.meta.url));
21
+ await ctx.exec(
22
+ "vitest",
23
+ ["--config", path.join(__dirname, "vitest.config.js"), ...args],
24
+ { env: {}, stdio: "inherit" },
25
+ );
23
26
  }
package/package.json CHANGED
@@ -1,31 +1,34 @@
1
1
  {
2
2
  "name": "@digigov/cli-test",
3
- "version": "2.0.0-rc.20",
3
+ "version": "2.0.0-rc.22",
4
4
  "description": "Test plugin for Digigov CLI",
5
5
  "main": "index.js",
6
+ "type": "module",
6
7
  "author": "GRNET Developers <devs@lists.grnet.gr>",
7
8
  "license": "BSD-2-Clause",
8
9
  "private": false,
9
10
  "dependencies": {
10
- "@types/jest": "29.0.2",
11
- "babel-jest": "29.0.2",
12
- "babel-plugin-istanbul": "7.0.0",
13
- "jest": "29.0.2",
14
- "jest-cli": "29.0.2",
15
11
  "publint": "0.1.8",
12
+ "@vitest/coverage-istanbul": "2.1.3",
16
13
  "@testing-library/jest-dom": "6.1.4",
17
- "@testing-library/react": "15.0.7",
18
- "jest-environment-jsdom": "29.0.2"
14
+ "vite-tsconfig-paths": "5.0.1"
19
15
  },
20
16
  "devDependencies": {
21
17
  "publint": "0.1.8"
22
18
  },
23
19
  "peerDependencies": {
24
- "@digigov/cli": "1.1.1-rc.20",
25
- "@digigov/cli-build": "2.0.0-rc.20",
26
- "typescript": "5.6.2",
27
- "@types/node": "18.19.0",
28
- "@types/react": "18.3.3"
20
+ "vitest": "2.1.3",
21
+ "@testing-library/dom": "10.4.0",
22
+ "@testing-library/react": "16.0.1",
23
+ "@digigov/cli": "2.0.0-rc.22"
24
+ },
25
+ "peerDependenciesMeta": {
26
+ "@testing-library/dom": {
27
+ "optional": true
28
+ },
29
+ "@testing-library/react": {
30
+ "optional": true
31
+ }
29
32
  },
30
33
  "scripts": {
31
34
  "publint": "publint"
package/test-setup.js ADDED
@@ -0,0 +1,10 @@
1
+ import * as path from "path";
2
+ import * as matchers from "@testing-library/jest-dom/matchers";
3
+ import { expect } from "vitest";
4
+
5
+ import { digest } from "./dirsum.js";
6
+
7
+ global.path = path;
8
+ global.digest = digest;
9
+
10
+ expect.extend(matchers);
@@ -0,0 +1,33 @@
1
+ import path from "path";
2
+ import { resolveProject } from "@digigov/cli/lib";
3
+ import { defineConfig } from "vitest/config";
4
+ import { fileURLToPath } from "url";
5
+ import tsconfigPaths from "vite-tsconfig-paths";
6
+
7
+ const __dirname = path.dirname(fileURLToPath(import.meta.url));
8
+
9
+ const project = resolveProject();
10
+
11
+ export default defineConfig({
12
+ test: {
13
+ globals: true,
14
+ watch: false,
15
+ environment: "jsdom",
16
+ setupFiles: path.resolve(__dirname, "test-setup.js"),
17
+ sequence: {
18
+ hooks: "list",
19
+ },
20
+ snapshotFormat: {
21
+ printBasicPrototype: true,
22
+ },
23
+ coverage: {
24
+ reporter: ["cobertura", "text"],
25
+ provider: "istanbul",
26
+ },
27
+ },
28
+ plugins: [
29
+ tsconfigPaths({
30
+ root: project.workspace.root,
31
+ }),
32
+ ],
33
+ });
@@ -1,4 +0,0 @@
1
- const babelrc = require('@digigov/cli-build/babel.config');
2
- const { createTransformer } = require('babel-jest');
3
-
4
- module.exports = createTransformer(babelrc);
package/jest.common.js DELETED
@@ -1,21 +0,0 @@
1
- const path = require("path");
2
- const lib = require("@digigov/cli/lib");
3
-
4
- function makeJestConfig(dir) {
5
- const project = lib.resolveProject(dir);
6
- const rootDir = project.root;
7
- return {
8
- testEnvironment: "jsdom",
9
- rootDir,
10
- transform: {
11
- "^.+\\.[t|j]sx?$": path.resolve(__dirname, "babelTransformer.js"),
12
- },
13
- setupFilesAfterEnv: [path.resolve(__dirname, "setupTests.js")],
14
- testPathIgnorePatterns: ["\\.history/.*", "dist"],
15
- };
16
- }
17
-
18
- module.exports = {
19
- makeJestConfig,
20
- config: makeJestConfig(),
21
- };
package/jest.config.js DELETED
@@ -1 +0,0 @@
1
- module.exports = require('./jest.common').config
package/setupTests.js DELETED
@@ -1,67 +0,0 @@
1
- var { spawn } = require("child_process");
2
- const { digest } = require("./dirsum");
3
- import "@testing-library/jest-dom";
4
-
5
- global["digest"] = digest;
6
-
7
- class Cli {
8
- constructor(options) {
9
- this.output = "";
10
- }
11
- async run(command, options) {
12
- return new Promise((resolve, reject) => {
13
- const child = spawn(command, options);
14
- child.stdout.on("data", (data) => {
15
- // console.log(this.output);
16
- this.output += data.toString();
17
- });
18
- this.command = child;
19
- resolve();
20
- });
21
- }
22
- getOutput() {
23
- return this.output;
24
- }
25
- }
26
- global.Cli = Cli;
27
- // console.log(Object.keys(global))
28
- const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
29
- global["expect"].extend({
30
- toSpawnCommand: async (cli, command, args) => {
31
- await cli.run(command, args);
32
- return {
33
- pass: true,
34
- message: () => `Spawned command ${command} ${args.join(" ")}`,
35
- };
36
- },
37
- toMatchContent: async (cli, text) => {
38
- while (true) {
39
- const lastLine = cli.getOutput();
40
- if (lastLine.match(text)) {
41
- break;
42
- }
43
- await sleep(100);
44
- }
45
- return {
46
- pass: true,
47
- message: () => `Matches ${text}`,
48
- };
49
- },
50
- toEnter: async (cli, text) => {
51
- const keyPress = {
52
- _UP_: "\x1B[A",
53
- _DOWN_: "\x1B[B",
54
- };
55
- if (keyPress[text]) {
56
- text = keyPress[text];
57
- }
58
- cli.command.stdin.write(text);
59
- cli.command.stdin.write("\n");
60
- return {
61
- pass: true,
62
- message: () => `Entered ${text}`,
63
- };
64
- },
65
- });
66
-
67
- global.path = require("path");