@digigov/cli-test 1.1.0 → 2.0.0-0138f8bd

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/dirsum.js CHANGED
@@ -1,72 +1,83 @@
1
- const crypto = require('crypto');
2
- const fs = require('fs');
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
- }
1
+ import crypto from 'crypto';
2
+ import fs from 'fs';
24
3
 
25
4
  const method = 'sha1';
26
- function digest(root, options) {
27
- if(!root || typeof (root) !== 'string') {
5
+
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') {
28
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) {
29
+ for (const f of files) {
43
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()) {
39
+ } else if (stats.isFile()) {
53
40
  const data = fs.readFileSync(path, 'utf8');
54
41
 
55
42
  const hash = crypto.createHash(method);
56
43
  hash.update(data);
57
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
50
  console.error('Skipping hash of %s', f);
64
- if(++hashed > files.length) {
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
+ */
62
+ function _summarize(method, hashes) {
63
+ const keys = Object.keys(hashes);
64
+ keys.sort();
65
+
66
+ const obj = {
67
+ files: hashes,
68
+ hash: '',
69
+ };
70
+ const hash = crypto.createHash(method);
71
+ for (const key of keys) {
72
+ if (typeof hashes[key] === 'string') {
73
+ hash.update(hashes[key]);
74
+ } else if (typeof hashes[key] === 'object') {
75
+ hash.update(hashes[key]['hash']);
76
+ } else {
77
+ console.error('Unknown type found in hash: ' + typeof hashes[key]);
78
+ }
79
+ }
80
+
81
+ obj['hash'] = hash.digest('hex');
82
+ return obj;
69
83
  }
70
- module.exports = {
71
- digest: digest
72
- };
@@ -0,0 +1,3 @@
1
+ import config from '@digigov/cli-lint/eslint.config';
2
+
3
+ export default [...config];
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,35 +1,43 @@
1
1
  {
2
2
  "name": "@digigov/cli-test",
3
- "version": "1.1.0",
3
+ "version": "2.0.0-0138f8bd",
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/enzyme": "3.10.8",
11
- "@types/enzyme-adapter-react-16": "1.0.5",
12
- "@types/jest": "26.0.15",
13
- "babel-jest": "26.6.3",
14
- "babel-plugin-istanbul": "6.0.0",
15
- "enzyme": "3.11.0",
16
- "enzyme-adapter-react-16": "1.15.2",
17
- "enzyme-to-json": "3.4.3",
18
- "jest": "26.6.3",
19
- "jest-cli": "26.6.3",
20
- "publint": "0.1.8"
11
+ "publint": "0.1.8",
12
+ "@vitest/coverage-istanbul": "2.1.3",
13
+ "@testing-library/jest-dom": "6.1.4",
14
+ "jsdom": "25.0.1"
21
15
  },
22
16
  "devDependencies": {
17
+ "@digigov/cli": "2.0.0-0138f8bd",
18
+ "@digigov/cli-lint": "2.0.0-0138f8bd",
19
+ "eslint": "9.16.0",
20
+ "prettier": "3.4.2",
21
+ "vitest": "2.1.3",
23
22
  "publint": "0.1.8"
24
23
  },
25
24
  "peerDependencies": {
26
- "@digigov/cli": "1.1.0",
27
- "@digigov/cli-build": "1.1.0",
28
- "typescript": "5.3.2",
29
- "@types/node": "16.6.2",
30
- "@types/react": "16.9.56"
25
+ "vitest": "2.1.3",
26
+ "@testing-library/dom": "10.4.0",
27
+ "@testing-library/react": "16.2.0",
28
+ "@digigov/cli": "2.0.0-0138f8bd"
29
+ },
30
+ "peerDependenciesMeta": {
31
+ "@testing-library/dom": {
32
+ "optional": true
33
+ },
34
+ "@testing-library/react": {
35
+ "optional": true
36
+ }
31
37
  },
32
38
  "scripts": {
33
- "publint": "publint"
39
+ "publint": "publint",
40
+ "lint": "digigov lint",
41
+ "typecheck": "tsc"
34
42
  }
35
43
  }
package/test-setup.js ADDED
@@ -0,0 +1,11 @@
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
+ // @ts-ignore
11
+ expect.extend(matchers);
package/tsconfig.json ADDED
@@ -0,0 +1,4 @@
1
+ {
2
+ "extends": "@digigov/cli/tsconfig.cli",
3
+ "include": ["./*.js"]
4
+ }
@@ -0,0 +1,41 @@
1
+ import path from 'path';
2
+ import fs from 'fs';
3
+ import { resolveProject } from '@digigov/cli/lib';
4
+ import { defineConfig } from 'vitest/config';
5
+ import { fileURLToPath } from 'url';
6
+
7
+ const __dirname = path.dirname(fileURLToPath(import.meta.url));
8
+
9
+ const project = resolveProject();
10
+
11
+ const tsconfigPath = path.join(project.root, 'tsconfig.json');
12
+ const tsconfig = JSON.parse(fs.readFileSync(tsconfigPath, 'utf8'));
13
+
14
+ const alias = Object.fromEntries(
15
+ Object.entries(tsconfig.compilerOptions.paths).map(([key, [value]]) => [
16
+ key.replace(/\/\*$/, ''),
17
+ path.resolve(project.root, value.replace(/\/\*$/, '')),
18
+ ])
19
+ );
20
+
21
+ export default defineConfig({
22
+ resolve: {
23
+ alias,
24
+ },
25
+ test: {
26
+ globals: true,
27
+ watch: false,
28
+ environment: 'jsdom',
29
+ setupFiles: path.resolve(__dirname, 'test-setup.js'),
30
+ sequence: {
31
+ hooks: 'list',
32
+ },
33
+ snapshotFormat: {
34
+ printBasicPrototype: true,
35
+ },
36
+ coverage: {
37
+ reporter: ['cobertura', 'text'],
38
+ provider: 'istanbul',
39
+ },
40
+ },
41
+ });
@@ -1,15 +0,0 @@
1
- {
2
- "files": {
3
- "tooling/cli-test/CHANGELOG.json": "b68c9ea29daf822ca9fa86ba4f217c3e143407d5",
4
- "tooling/cli-test/CHANGELOG.md": "c6dcf53cb759736582a8512323baecc27f8284a3",
5
- "tooling/cli-test/babelTransformer.js": "271e13591a0aaca483eb49e043c567107b58e4b2",
6
- "tooling/cli-test/dirsum.js": "a94b73135c0c3813aa986136cfc0280f47be383e",
7
- "tooling/cli-test/index.js": "8b1c22589b41f7defd89757e5cb24045c271ae07",
8
- "tooling/cli-test/jest.common.js": "a0e0f68855647bccf3492423632519ad9f1d2bb1",
9
- "tooling/cli-test/jest.config.js": "4e614114a0600f0293ac9569739bf708fb742ba9",
10
- "tooling/cli-test/package.json": "e4cd9e0ea4808eaca47d178c9ed7041892fff92e",
11
- "tooling/cli-test/setupTests.js": "ce2d70b8bb1a75d11370ae65b32dff9b9c4e21f4",
12
- "tooling/cli-test/.rush/temp/shrinkwrap-deps.json": "f6053570d951206e32e09c3d9d0e866fbfff0114"
13
- },
14
- "arguments": "publint "
15
- }
@@ -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);
@@ -1,3 +0,0 @@
1
- Invoking: publint
2
- @digigov/cli-test lint results:
3
- All good!
package/jest.common.js DELETED
@@ -1,24 +0,0 @@
1
- const path = require('path');
2
- const lib = require('@digigov/cli/lib');
3
- function makeJestConfig(dir) {
4
- const project = lib.resolveProject(dir);
5
- const rootDir = project.root;
6
- let roots = [path.join(project.root, project.src)];
7
- return {
8
- rootDir,
9
- transform: {
10
- '^.+\\.[t|j]sx?$': path.resolve(
11
- __dirname,
12
- 'babelTransformer.js'
13
- ),
14
- },
15
- "setupFilesAfterEnv": [path.resolve(__dirname, 'setupTests.js')],
16
- snapshotSerializers: ['enzyme-to-json/serializer'],
17
- testPathIgnorePatterns: ['\\.history/.*', 'dist'],
18
- };
19
- }
20
-
21
- module.exports = {
22
- makeJestConfig,
23
- config: makeJestConfig(),
24
- };
package/jest.config.js DELETED
@@ -1 +0,0 @@
1
- module.exports = require('./jest.common').config
package/setupTests.js DELETED
@@ -1,70 +0,0 @@
1
- const { configure } = require('enzyme');
2
- const React16Adapter = require('enzyme-adapter-react-16');
3
- var {spawn} = require('child_process');
4
- const {digest} = require('./dirsum')
5
-
6
- global['digest'] = digest
7
-
8
- class Cli {
9
- constructor(options) {
10
- this.output = '';
11
- }
12
- async run(command, options) {
13
- return new Promise((resolve, reject) => {
14
- const child = spawn(command, options);
15
- child.stdout.on('data', data => {
16
- // console.log(this.output);
17
- this.output += data.toString();
18
- });
19
- this.command = child
20
- resolve()
21
- });
22
- }
23
- getOutput() {
24
- return this.output;
25
- }
26
- }
27
- global.Cli = Cli;
28
- configure({ adapter: new React16Adapter() });
29
- // console.log(Object.keys(global))
30
- const sleep = (ms) => new Promise(resolve => setTimeout(resolve, ms));
31
- global['expect'].extend({
32
- toSpawnCommand: async (cli, command, args) => {
33
- await cli.run(command, args);
34
- return {
35
- pass: true,
36
- message: () => `Spawned command ${command} ${args.join(' ')}`
37
- }
38
- },
39
- toMatchContent: async (cli, text)=>{
40
- while(true ){
41
- const lastLine = cli.getOutput();
42
- if(lastLine.match(text)){
43
- break
44
- }
45
- await sleep(100)
46
- }
47
- return {
48
- pass: true,
49
- message: () => `Matches ${text}`
50
- }
51
- },
52
- toEnter: async (cli, text)=>{
53
- const keyPress ={
54
- '_UP_': '\x1B[A',
55
- '_DOWN_': '\x1B[B',
56
- }
57
- if(keyPress[text]){
58
- text = keyPress[text]
59
- }
60
- cli.command.stdin.write(text);
61
- cli.command.stdin.write('\n');
62
- return {
63
- pass: true,
64
- message: () => `Entered ${text}`
65
- }
66
- }
67
- })
68
-
69
- global.path = require('path')
70
-