ic-mops 1.8.1 → 1.10.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.
Files changed (52) hide show
  1. package/.DS_Store +0 -0
  2. package/.dockerignore +3 -0
  3. package/CHANGELOG.md +10 -0
  4. package/bun.lock +1278 -0
  5. package/bundle/bench/bench-canister.mo +109 -101
  6. package/bundle/bench/user-bench.mo +6 -6
  7. package/bundle/cli.js +1793 -909
  8. package/bundle/cli.tgz +0 -0
  9. package/bundle/declarations/main/main.did +6 -0
  10. package/bundle/declarations/main/main.did.d.ts +6 -0
  11. package/bundle/declarations/main/main.did.js +6 -0
  12. package/bundle/package.json +1 -1
  13. package/bundle/templates/src/lib.mo +13 -13
  14. package/bundle/templates/test/lib.test.mo +2 -2
  15. package/bundle/xhr-sync-worker.js +59 -0
  16. package/cli.ts +28 -0
  17. package/commands/bench-replica.ts +1 -0
  18. package/commands/docs-coverage.ts +110 -0
  19. package/commands/docs.ts +47 -20
  20. package/commands/publish.ts +25 -2
  21. package/commands/test/test.ts +2 -1
  22. package/commands/toolchain/moc.ts +10 -4
  23. package/declarations/main/main.did +6 -0
  24. package/declarations/main/main.did.d.ts +6 -0
  25. package/declarations/main/main.did.js +6 -0
  26. package/dist/cli.js +25 -0
  27. package/dist/commands/bench-replica.js +6 -2
  28. package/dist/commands/docs-coverage.d.ts +8 -0
  29. package/dist/commands/docs-coverage.js +86 -0
  30. package/dist/commands/docs.d.ts +9 -3
  31. package/dist/commands/docs.js +34 -17
  32. package/dist/commands/publish.js +23 -2
  33. package/dist/commands/replica.js +8 -7
  34. package/dist/commands/test/mmf1.js +14 -12
  35. package/dist/commands/test/reporters/compact-reporter.js +50 -63
  36. package/dist/commands/test/reporters/files-reporter.js +5 -14
  37. package/dist/commands/test/reporters/silent-reporter.js +10 -10
  38. package/dist/commands/test/reporters/verbose-reporter.js +7 -23
  39. package/dist/commands/test/test.js +1 -0
  40. package/dist/commands/toolchain/moc.js +10 -4
  41. package/dist/commands/watch/deployer.js +10 -7
  42. package/dist/commands/watch/error-checker.js +4 -4
  43. package/dist/commands/watch/formatter.js +7 -4
  44. package/dist/commands/watch/generator.js +9 -7
  45. package/dist/commands/watch/tester.js +7 -5
  46. package/dist/commands/watch/warning-checker.js +8 -6
  47. package/dist/declarations/main/main.did +6 -0
  48. package/dist/declarations/main/main.did.d.ts +6 -0
  49. package/dist/declarations/main/main.did.js +6 -0
  50. package/dist/package.json +13 -11
  51. package/package.json +15 -13
  52. package/tsconfig.json +2 -1
@@ -124,6 +124,7 @@ export interface Main {
124
124
  [Text, [] | [bigint], [] | [bigint]],
125
125
  [Array<PackageSummary>, PageCount]
126
126
  >,
127
+ 'setStorageControllers' : ActorMethod<[], undefined>,
127
128
  'setUserProp' : ActorMethod<[string, string], Result_3>,
128
129
  'startFileUpload' : ActorMethod<
129
130
  [PublishingId, Text, bigint, Uint8Array | number[]],
@@ -132,6 +133,7 @@ export interface Main {
132
133
  'startPublish' : ActorMethod<[PackageConfigV3_Publishing], Result_1>,
133
134
  'transformRequest' : ActorMethod<[HttpTransformArg], HttpResponse>,
134
135
  'uploadBenchmarks' : ActorMethod<[PublishingId, Benchmarks], Result>,
136
+ 'uploadDocsCoverage' : ActorMethod<[PublishingId, number], Result>,
135
137
  'uploadFileChunk' : ActorMethod<
136
138
  [PublishingId, FileId, bigint, Uint8Array | number[]],
137
139
  Result
@@ -143,8 +145,10 @@ export interface PackageChanges {
143
145
  'tests' : TestsChanges,
144
146
  'deps' : Array<DepChange>,
145
147
  'curBenchmarks' : Benchmarks__1,
148
+ 'prevDocsCoverage' : number,
146
149
  'prevBenchmarks' : Benchmarks__1,
147
150
  'notes' : string,
151
+ 'curDocsCoverage' : number,
148
152
  'devDeps' : Array<DepChange>,
149
153
  }
150
154
  export interface PackageConfigV3 {
@@ -196,6 +200,7 @@ export interface PackageDetails {
196
200
  'quality' : PackageQuality,
197
201
  'publisher' : User,
198
202
  'testStats' : TestStats__1,
203
+ 'docsCoverage' : number,
199
204
  'highestVersion' : PackageVersion,
200
205
  'downloadsTotal' : bigint,
201
206
  'downloadsInLast30Days' : bigint,
@@ -223,6 +228,7 @@ export interface PackagePublication {
223
228
  }
224
229
  export interface PackageQuality {
225
230
  'depsStatus' : DepsStatus,
231
+ 'docsCoverage' : number,
226
232
  'hasDescription' : boolean,
227
233
  'hasKeywords' : boolean,
228
234
  'hasLicense' : boolean,
@@ -48,6 +48,7 @@ export const idlFactory = ({ IDL }) => {
48
48
  });
49
49
  const PackageQuality = IDL.Record({
50
50
  'depsStatus' : DepsStatus,
51
+ 'docsCoverage' : IDL.Float64,
51
52
  'hasDescription' : IDL.Bool,
52
53
  'hasKeywords' : IDL.Bool,
53
54
  'hasLicense' : IDL.Bool,
@@ -161,8 +162,10 @@ export const idlFactory = ({ IDL }) => {
161
162
  'tests' : TestsChanges,
162
163
  'deps' : IDL.Vec(DepChange),
163
164
  'curBenchmarks' : Benchmarks__1,
165
+ 'prevDocsCoverage' : IDL.Float64,
164
166
  'prevBenchmarks' : Benchmarks__1,
165
167
  'notes' : IDL.Text,
168
+ 'curDocsCoverage' : IDL.Float64,
166
169
  'devDeps' : IDL.Vec(DepChange),
167
170
  });
168
171
  const PackageSummaryWithChanges__1 = IDL.Record({
@@ -192,6 +195,7 @@ export const idlFactory = ({ IDL }) => {
192
195
  'quality' : PackageQuality,
193
196
  'publisher' : User,
194
197
  'testStats' : TestStats__1,
198
+ 'docsCoverage' : IDL.Float64,
195
199
  'highestVersion' : PackageVersion,
196
200
  'downloadsTotal' : IDL.Nat,
197
201
  'downloadsInLast30Days' : IDL.Nat,
@@ -428,6 +432,7 @@ export const idlFactory = ({ IDL }) => {
428
432
  [IDL.Vec(PackageSummary), PageCount],
429
433
  ['query'],
430
434
  ),
435
+ 'setStorageControllers' : IDL.Func([], [], []),
431
436
  'setUserProp' : IDL.Func([IDL.Text, IDL.Text], [Result_3], []),
432
437
  'startFileUpload' : IDL.Func(
433
438
  [PublishingId, Text, IDL.Nat, IDL.Vec(IDL.Nat8)],
@@ -441,6 +446,7 @@ export const idlFactory = ({ IDL }) => {
441
446
  ['query'],
442
447
  ),
443
448
  'uploadBenchmarks' : IDL.Func([PublishingId, Benchmarks], [Result], []),
449
+ 'uploadDocsCoverage' : IDL.Func([PublishingId, IDL.Float64], [Result], []),
444
450
  'uploadFileChunk' : IDL.Func(
445
451
  [PublishingId, FileId, IDL.Nat, IDL.Vec(IDL.Nat8)],
446
452
  [Result],
package/dist/cli.js CHANGED
@@ -28,6 +28,8 @@ import { watch } from './commands/watch/watch.js';
28
28
  import { addOwner, printOwners, removeOwner } from './commands/owner.js';
29
29
  import { addMaintainer, printMaintainers, removeMaintainer } from './commands/maintainer.js';
30
30
  import { format } from './commands/format.js';
31
+ import { docs } from './commands/docs.js';
32
+ import { docsCoverage } from './commands/docs-coverage.js';
31
33
  events.setMaxListeners(20);
32
34
  let networkFile = getNetworkFile();
33
35
  if (fs.existsSync(networkFile)) {
@@ -426,4 +428,27 @@ program
426
428
  process.exit(1);
427
429
  }
428
430
  });
431
+ // docs
432
+ const docsCommand = new Command('docs').description('Documentation management');
433
+ docsCommand
434
+ .command('generate')
435
+ .description('Generate documentation for Motoko code')
436
+ .addOption(new Option('--source <source>', 'Source directory').default('src'))
437
+ .addOption(new Option('--output <output>', 'Output directory').default('docs'))
438
+ .addOption(new Option('--format <format>', 'Output format').default('md').choices(['md', 'adoc', 'html']))
439
+ .action(async (options) => {
440
+ checkConfigFile(true);
441
+ await docs(options);
442
+ });
443
+ docsCommand
444
+ .command('coverage')
445
+ .description('Documentation coverage report')
446
+ .addOption(new Option('-s, --source <source>', 'Source directory (with .mo files)').default('src'))
447
+ .addOption(new Option('-r, --reporter <reporter>', 'Coverage reporter').choices(['files', 'compact', 'missing', 'verbose']).default('files'))
448
+ .addOption(new Option('-t, --threshold <threshold>', 'Coverage threshold (0-100). If total coverage is below threshold, exit with error code 1').default(70))
449
+ .action(async (options) => {
450
+ checkConfigFile(true);
451
+ await docsCoverage(options);
452
+ });
453
+ program.addCommand(docsCommand);
429
454
  program.parse();
@@ -9,9 +9,12 @@ import { createActor, idlFactory } from '../declarations/bench/index.js';
9
9
  import { toolchain } from './toolchain/index.js';
10
10
  import { getDfxVersion } from '../helpers/get-dfx-version.js';
11
11
  export class BenchReplica {
12
+ type;
13
+ verbose = false;
14
+ canisters = {};
15
+ pocketIcServer;
16
+ pocketIc;
12
17
  constructor(type, verbose = false) {
13
- this.verbose = false;
14
- this.canisters = {};
15
18
  this.type = type;
16
19
  this.verbose = verbose;
17
20
  }
@@ -81,6 +84,7 @@ export class BenchReplica {
81
84
  type: 'custom',
82
85
  wasm: 'canister.wasm',
83
86
  candid: 'canister.did',
87
+ optimize: 'cycles',
84
88
  };
85
89
  }
86
90
  return {
@@ -0,0 +1,8 @@
1
+ export type DocsCoverageReporter = 'compact' | 'files' | 'missing' | 'verbose' | 'silent';
2
+ type DocsCoverageOptions = {
3
+ source: string;
4
+ reporter: DocsCoverageReporter;
5
+ threshold: number;
6
+ };
7
+ export declare function docsCoverage(options?: Partial<DocsCoverageOptions>): Promise<number>;
8
+ export {};
@@ -0,0 +1,86 @@
1
+ import { readFileSync } from 'node:fs';
2
+ import chalk from 'chalk';
3
+ import { globSync } from 'glob';
4
+ import { JSDOM } from 'jsdom';
5
+ import { docs } from './docs.js';
6
+ export async function docsCoverage(options = {}) {
7
+ let docsDir = '.mops/.docs';
8
+ let { source, reporter, threshold } = {
9
+ source: 'src',
10
+ reporter: 'files',
11
+ threshold: 0,
12
+ ...options,
13
+ };
14
+ await docs({
15
+ source,
16
+ output: docsDir,
17
+ format: 'html',
18
+ silent: true,
19
+ });
20
+ let files = globSync(`${docsDir}/**/*.html`, { ignore: [`${docsDir}/**/index.html`] });
21
+ let coverages = [];
22
+ for (let file of files) {
23
+ let coverage = docFileCoverage(file);
24
+ coverages.push(coverage);
25
+ if (reporter === 'silent') {
26
+ continue;
27
+ }
28
+ if (reporter !== 'compact' && (reporter !== 'missing' || coverage.coverage < 100)) {
29
+ console.log(`• ${coverage.file} ${colorizeCoverage(coverage.coverage)}`);
30
+ }
31
+ if (reporter === 'missing' && coverage.coverage < 100) {
32
+ for (let item of coverage.items) {
33
+ if (!item.covered) {
34
+ console.log(` ${item.covered ? chalk.green('✓') : chalk.red('✖')} ${item.id} ${chalk.gray(item.type)}`);
35
+ }
36
+ }
37
+ }
38
+ else if (reporter === 'verbose') {
39
+ for (let item of coverage.items) {
40
+ console.log(` ${item.covered ? chalk.green('✓') : chalk.red('✖')} ${item.id} ${chalk.gray(item.type)}`);
41
+ }
42
+ }
43
+ }
44
+ if (reporter !== 'compact' && reporter !== 'silent') {
45
+ console.log('-'.repeat(50));
46
+ }
47
+ let totalCoverage = coverages.reduce((acc, coverage) => acc + coverage.coverage, 0) / (coverages.length || 1);
48
+ if (reporter !== 'silent') {
49
+ console.log(`Documentation coverage: ${colorizeCoverage(totalCoverage)}`);
50
+ }
51
+ if (threshold > 0 && totalCoverage < threshold) {
52
+ process.exit(1);
53
+ }
54
+ return totalCoverage;
55
+ }
56
+ function docFileCoverage(file) {
57
+ let dom = new JSDOM(readFileSync(file, 'utf-8'));
58
+ let module = dom.window.document.querySelector('h1')?.textContent || '';
59
+ let moduleFile = `${module}.mo`;
60
+ let items = [...dom.window.document.querySelectorAll('h4')].map(h4 => {
61
+ let id = h4.getAttribute('id')?.replace('type.', '');
62
+ let type = h4.className.replace('-declaration', '').replace('function', 'func');
63
+ let definition = h4.textContent;
64
+ let comment = h4.parentElement?.querySelector('p + p')?.textContent;
65
+ return { file: moduleFile, id, type, definition, comment, covered: (comment || '').length >= 5 };
66
+ });
67
+ let coverage = 0;
68
+ if (!items.length) {
69
+ coverage = 100;
70
+ }
71
+ else {
72
+ coverage = items.filter(item => item.covered).length / items.length * 100;
73
+ }
74
+ return { file: moduleFile, coverage, items };
75
+ }
76
+ function colorizeCoverage(coverage) {
77
+ if (coverage >= 90) {
78
+ return chalk.green(coverage.toFixed(2) + '%');
79
+ }
80
+ else if (coverage >= 50) {
81
+ return chalk.yellow(coverage.toFixed(2) + '%');
82
+ }
83
+ else {
84
+ return chalk.red(coverage.toFixed(2) + '%');
85
+ }
86
+ }
@@ -1,3 +1,9 @@
1
- export declare function docs({ silent }?: {
2
- silent?: boolean | undefined;
3
- }): Promise<void>;
1
+ type DocsOptions = {
2
+ source: string;
3
+ output: string;
4
+ format: 'md' | 'adoc' | 'html';
5
+ silent: boolean;
6
+ archive: boolean;
7
+ };
8
+ export declare function docs(options?: Partial<DocsOptions>): Promise<void>;
9
+ export {};
@@ -10,9 +10,20 @@ import streamToPromise from 'stream-to-promise';
10
10
  import { getRootDir } from '../mops.js';
11
11
  import { toolchain } from './toolchain/index.js';
12
12
  let moDocPath;
13
- export async function docs({ silent = false } = {}) {
13
+ export async function docs(options = {}) {
14
+ let { source, output, format, silent, archive } = {
15
+ source: 'src',
16
+ output: '.mops/.docs',
17
+ format: 'adoc',
18
+ silent: false,
19
+ archive: false,
20
+ ...options,
21
+ };
22
+ if (format === 'md') {
23
+ format = 'plain';
24
+ }
14
25
  let rootDir = getRootDir();
15
- let docsDir = path.join(rootDir, '.mops/.docs');
26
+ let docsDir = path.join(rootDir, output);
16
27
  let docsDirRelative = path.relative(process.cwd(), docsDir);
17
28
  deleteSync([docsDir], { force: true });
18
29
  // detect mocv (legacy)
@@ -26,13 +37,17 @@ export async function docs({ silent = false } = {}) {
26
37
  }
27
38
  // generate docs
28
39
  await new Promise((resolve) => {
29
- let proc = spawn(moDocPath, [`--source=${path.join(rootDir, 'src')}`, `--output=${docsDirRelative}`, '--format=adoc']);
40
+ let proc = spawn(moDocPath, [
41
+ `--source=${path.join(rootDir, source)}`,
42
+ `--output=${docsDirRelative}`,
43
+ `--format=${format}`,
44
+ ]);
30
45
  // stdout
31
46
  proc.stdout.on('data', (data) => {
32
47
  let text = data.toString().trim();
33
48
  let failedText = 'Failed to extract documentation';
34
49
  if (text.includes(failedText)) {
35
- console.log(text.replaceAll(failedText, chalk.yellow('Warning: ') + failedText));
50
+ silent || console.log(text.replaceAll(failedText, chalk.yellow('Warning: ') + failedText));
36
51
  }
37
52
  silent || console.log('stdout', text);
38
53
  });
@@ -65,19 +80,21 @@ export async function docs({ silent = false } = {}) {
65
80
  });
66
81
  });
67
82
  // create archive
68
- let ignore = [
69
- `${docsDir}/**/*.test.adoc`,
70
- `${docsDir}/test/**/*`,
71
- ];
72
- let files = globSync(`${docsDir}/**/*.adoc`, { ignore }).map(f => path.relative(docsDir, f));
73
- files.sort();
74
- if (files.length) {
75
- let stream = createTar({
76
- cwd: docsDir,
77
- gzip: true,
78
- portable: true,
79
- }, files).pipe(fs.createWriteStream(path.join(docsDir, 'docs.tgz')));
80
- await streamToPromise(stream);
83
+ if (archive) {
84
+ let ignore = [
85
+ `${docsDir}/**/*.test.adoc`,
86
+ `${docsDir}/test/**/*`,
87
+ ];
88
+ let files = globSync(`${docsDir}/**/*.adoc`, { ignore }).map(f => path.relative(docsDir, f));
89
+ files.sort();
90
+ if (files.length) {
91
+ let stream = createTar({
92
+ cwd: docsDir,
93
+ gzip: true,
94
+ portable: true,
95
+ }, files).pipe(fs.createWriteStream(path.join(docsDir, 'docs.tgz')));
96
+ await streamToPromise(stream);
97
+ }
81
98
  }
82
99
  silent || console.log(`${chalk.green('Documentation generated')} at ${docsDirRelative}`);
83
100
  }
@@ -14,6 +14,7 @@ import { testWithReporter } from './test/test.js';
14
14
  import { SilentReporter } from './test/reporters/silent-reporter.js';
15
15
  import { findChangelogEntry } from '../helpers/find-changelog-entry.js';
16
16
  import { bench } from './bench.js';
17
+ import { docsCoverage } from './docs-coverage.js';
17
18
  export async function publish(options = {}) {
18
19
  if (!checkConfigFile()) {
19
20
  return;
@@ -43,7 +44,7 @@ export async function publish(options = {}) {
43
44
  // desired fields
44
45
  for (let key of ['description', 'repository']) {
45
46
  // @ts-ignore
46
- if (!config.package[key]) {
47
+ if (!config.package[key] && !process.env.CI) {
47
48
  let res = await prompts({
48
49
  type: 'confirm',
49
50
  name: 'ok',
@@ -112,6 +113,18 @@ export async function publish(options = {}) {
112
113
  }
113
114
  delete dep.path;
114
115
  }
116
+ for (let dep of Object.values(config.dependencies)) {
117
+ if (dep.repo && !process.env.CI) {
118
+ let res = await prompts({
119
+ type: 'confirm',
120
+ name: 'ok',
121
+ message: chalk.yellow('GitHub dependencies make the registry less reliable and limit its capabilities.\nIf you are the owner of the dependency, please consider publishing it to the Mops registry.') + '\n\nPublish anyway?',
122
+ });
123
+ if (!res.ok) {
124
+ return;
125
+ }
126
+ }
127
+ }
115
128
  }
116
129
  if (config['dev-dependencies']) {
117
130
  if (Object.keys(config['dev-dependencies']).length > 100) {
@@ -205,9 +218,13 @@ export async function publish(options = {}) {
205
218
  }
206
219
  // generate docs
207
220
  let docsFile = path.join(rootDir, '.mops/.docs/docs.tgz');
221
+ let docsCov = 0;
208
222
  if (options.docs) {
209
223
  console.log('Generating documentation...');
210
- await docs({ silent: true });
224
+ docsCov = await docsCoverage({
225
+ reporter: 'silent',
226
+ });
227
+ await docs({ silent: true, archive: true });
211
228
  if (fs.existsSync(docsFile)) {
212
229
  files.unshift(docsFile);
213
230
  }
@@ -299,6 +316,10 @@ export async function publish(options = {}) {
299
316
  if (changelog) {
300
317
  await actor.uploadNotes(puiblishingId, changelog);
301
318
  }
319
+ // upload docs coverage
320
+ if (options.docs) {
321
+ await actor.uploadDocsCoverage(puiblishingId, docsCov);
322
+ }
302
323
  // upload files
303
324
  await parallel(8, files, async (file) => {
304
325
  progress();
@@ -11,13 +11,14 @@ import { readConfig } from '../mops.js';
11
11
  import { toolchain } from './toolchain/index.js';
12
12
  import { getDfxVersion } from '../helpers/get-dfx-version.js';
13
13
  export class Replica {
14
- constructor() {
15
- this.type = 'dfx';
16
- this.verbose = false;
17
- this.canisters = {};
18
- this.dir = ''; // absolute path (/.../.mops/.test/)
19
- this.ttl = 60;
20
- }
14
+ type = 'dfx';
15
+ verbose = false;
16
+ canisters = {};
17
+ pocketIcServer;
18
+ pocketIc;
19
+ dfxProcess;
20
+ dir = ''; // absolute path (/.../.mops/.test/)
21
+ ttl = 60;
21
22
  async start({ type, dir, verbose, silent } = {}) {
22
23
  this.type = type ?? this.type;
23
24
  this.verbose = verbose ?? this.verbose;
@@ -4,19 +4,21 @@
4
4
  // mops:1:skip
5
5
  import chalk from 'chalk';
6
6
  export class MMF1 {
7
+ file;
8
+ stack = [];
9
+ currSuite = '';
10
+ failed = 0;
11
+ passed = 0;
12
+ skipped = 0;
13
+ strategy;
14
+ output = [];
15
+ nestingSymbol = ' › ';
16
+ // or <file>
17
+ // or <file> › <test>
18
+ // or <file> › <suite> › <test>
19
+ // or <file> › <suite> › <test> › <nested-test>...
20
+ passedNamesFlat = [];
7
21
  constructor(strategy, file) {
8
- this.stack = [];
9
- this.currSuite = '';
10
- this.failed = 0;
11
- this.passed = 0;
12
- this.skipped = 0;
13
- this.output = [];
14
- this.nestingSymbol = ' › ';
15
- // or <file>
16
- // or <file> › <test>
17
- // or <file> › <suite> › <test>
18
- // or <file> › <suite> › <test> › <nested-test>...
19
- this.passedNamesFlat = [];
20
22
  this.strategy = strategy;
21
23
  this.file = file;
22
24
  }
@@ -1,41 +1,25 @@
1
- var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
2
- if (kind === "m") throw new TypeError("Private method is not writable");
3
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
4
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
5
- return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
6
- };
7
- var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
8
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
9
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
10
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
11
- };
12
- var _CompactReporter_instances, _CompactReporter_allFiles, _CompactReporter_runningFiles, _CompactReporter_failedFiles, _CompactReporter_finishedFiles, _CompactReporter_startTime, _CompactReporter_timerId, _CompactReporter_startTimer, _CompactReporter_clearTimer, _CompactReporter_log;
13
1
  import chalk from 'chalk';
14
2
  import logUpdate from 'log-update';
15
3
  import { absToRel } from '../utils.js';
16
4
  export class CompactReporter {
17
- constructor() {
18
- _CompactReporter_instances.add(this);
19
- this.passed = 0;
20
- this.failed = 0;
21
- this.skipped = 0;
22
- this.passedFiles = 0;
23
- this.failedFiles = 0;
24
- _CompactReporter_allFiles.set(this, new Set());
25
- _CompactReporter_runningFiles.set(this, new Set());
26
- _CompactReporter_failedFiles.set(this, new Set());
27
- _CompactReporter_finishedFiles.set(this, new Set());
28
- _CompactReporter_startTime.set(this, Date.now());
29
- _CompactReporter_timerId.set(this, null);
30
- }
5
+ passed = 0;
6
+ failed = 0;
7
+ skipped = 0;
8
+ passedFiles = 0;
9
+ failedFiles = 0;
10
+ #allFiles = new Set();
11
+ #runningFiles = new Set();
12
+ #failedFiles = new Set();
13
+ #finishedFiles = new Set();
14
+ #startTime = Date.now();
31
15
  addFiles(files) {
32
- __classPrivateFieldSet(this, _CompactReporter_allFiles, new Set(files), "f");
33
- __classPrivateFieldGet(this, _CompactReporter_instances, "m", _CompactReporter_log).call(this);
34
- __classPrivateFieldGet(this, _CompactReporter_instances, "m", _CompactReporter_startTimer).call(this);
16
+ this.#allFiles = new Set(files);
17
+ this.#log();
18
+ this.#startTimer();
35
19
  }
36
20
  addRun(file, mmf, state, _mode) {
37
- __classPrivateFieldGet(this, _CompactReporter_runningFiles, "f").add(file);
38
- __classPrivateFieldGet(this, _CompactReporter_instances, "m", _CompactReporter_log).call(this);
21
+ this.#runningFiles.add(file);
22
+ this.#log();
39
23
  state.then(() => {
40
24
  this.passed += mmf.passed;
41
25
  this.failed += mmf.failed;
@@ -46,50 +30,53 @@ export class CompactReporter {
46
30
  this.passedFiles += Number(mmf.failed === 0);
47
31
  this.failedFiles += Number(mmf.failed !== 0);
48
32
  if (mmf.failed) {
49
- __classPrivateFieldGet(this, _CompactReporter_failedFiles, "f").add(file);
33
+ this.#failedFiles.add(file);
50
34
  logUpdate.clear();
51
35
  console.log(chalk.red('✖'), absToRel(file));
52
36
  mmf.flush('fail');
53
37
  console.log('-'.repeat(50));
54
38
  }
55
- __classPrivateFieldGet(this, _CompactReporter_runningFiles, "f").delete(file);
56
- __classPrivateFieldGet(this, _CompactReporter_finishedFiles, "f").add(file);
57
- __classPrivateFieldGet(this, _CompactReporter_instances, "m", _CompactReporter_log).call(this);
39
+ this.#runningFiles.delete(file);
40
+ this.#finishedFiles.add(file);
41
+ this.#log();
58
42
  });
59
43
  }
60
44
  done() {
61
- __classPrivateFieldGet(this, _CompactReporter_instances, "m", _CompactReporter_log).call(this);
45
+ this.#log();
62
46
  logUpdate.done();
63
- __classPrivateFieldGet(this, _CompactReporter_instances, "m", _CompactReporter_clearTimer).call(this);
47
+ this.#clearTimer();
64
48
  return this.failed === 0;
65
49
  }
66
- }
67
- _CompactReporter_allFiles = new WeakMap(), _CompactReporter_runningFiles = new WeakMap(), _CompactReporter_failedFiles = new WeakMap(), _CompactReporter_finishedFiles = new WeakMap(), _CompactReporter_startTime = new WeakMap(), _CompactReporter_timerId = new WeakMap(), _CompactReporter_instances = new WeakSet(), _CompactReporter_startTimer = function _CompactReporter_startTimer() {
68
- __classPrivateFieldSet(this, _CompactReporter_timerId, setInterval(() => __classPrivateFieldGet(this, _CompactReporter_instances, "m", _CompactReporter_log).call(this), 55), "f");
69
- }, _CompactReporter_clearTimer = function _CompactReporter_clearTimer() {
70
- if (__classPrivateFieldGet(this, _CompactReporter_timerId, "f")) {
71
- clearInterval(__classPrivateFieldGet(this, _CompactReporter_timerId, "f"));
50
+ #timerId = null;
51
+ #startTimer() {
52
+ this.#timerId = setInterval(() => this.#log(), 55);
72
53
  }
73
- }, _CompactReporter_log = function _CompactReporter_log() {
74
- let res = [];
75
- let i = 0;
76
- for (let file of __classPrivateFieldGet(this, _CompactReporter_allFiles, "f")) {
77
- if (__classPrivateFieldGet(this, _CompactReporter_runningFiles, "f").has(file)) {
78
- res[Number(i)] = '.';
54
+ #clearTimer() {
55
+ if (this.#timerId) {
56
+ clearInterval(this.#timerId);
79
57
  }
80
- else if (__classPrivateFieldGet(this, _CompactReporter_finishedFiles, "f").has(file)) {
81
- res[Number(i)] = __classPrivateFieldGet(this, _CompactReporter_failedFiles, "f").has(file) ? chalk.red(':') : ':';
82
- }
83
- else {
84
- res[Number(i)] = ' ';
58
+ }
59
+ #log() {
60
+ let res = [];
61
+ let i = 0;
62
+ for (let file of this.#allFiles) {
63
+ if (this.#runningFiles.has(file)) {
64
+ res[Number(i)] = '.';
65
+ }
66
+ else if (this.#finishedFiles.has(file)) {
67
+ res[Number(i)] = this.#failedFiles.has(file) ? chalk.red(':') : ':';
68
+ }
69
+ else {
70
+ res[Number(i)] = ' ';
71
+ }
72
+ i++;
85
73
  }
86
- i++;
74
+ let output = `[${res.join('')}]\n`
75
+ + `${chalk.gray(((Date.now() - this.#startTime) / 1000).toFixed(2) + 's')}`
76
+ + `, total ${this.#allFiles.size} files`
77
+ + `, passed ${chalk.greenBright(this.passedFiles)} files`
78
+ + (this.skipped ? `, skipped ${chalk[this.skipped ? 'yellowBright' : 'gray'](this.skipped)} cases` : '')
79
+ + (this.failed ? `, failed ${chalk[this.failed ? 'redBright' : 'gray'](this.failed)} cases` : '');
80
+ logUpdate(output);
87
81
  }
88
- let output = `[${res.join('')}]\n`
89
- + `${chalk.gray(((Date.now() - __classPrivateFieldGet(this, _CompactReporter_startTime, "f")) / 1000).toFixed(2) + 's')}`
90
- + `, total ${__classPrivateFieldGet(this, _CompactReporter_allFiles, "f").size} files`
91
- + `, passed ${chalk.greenBright(this.passedFiles)} files`
92
- + (this.skipped ? `, skipped ${chalk[this.skipped ? 'yellowBright' : 'gray'](this.skipped)} cases` : '')
93
- + (this.failed ? `, failed ${chalk[this.failed ? 'redBright' : 'gray'](this.failed)} cases` : '');
94
- logUpdate(output);
95
- };
82
+ }
@@ -1,18 +1,10 @@
1
- var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
2
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
3
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
4
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
5
- };
6
- var _FilesReporter_startTime;
7
1
  import chalk from 'chalk';
8
2
  import { absToRel } from '../utils.js';
9
3
  export class FilesReporter {
10
- constructor() {
11
- this.passed = 0;
12
- this.failed = 0;
13
- this.skipped = 0;
14
- _FilesReporter_startTime.set(this, Date.now());
15
- }
4
+ passed = 0;
5
+ failed = 0;
6
+ skipped = 0;
7
+ #startTime = Date.now();
16
8
  addFiles(files) {
17
9
  console.log(`Test files: ${files.length}`);
18
10
  console.log('='.repeat(50));
@@ -40,11 +32,10 @@ export class FilesReporter {
40
32
  else {
41
33
  console.log(chalk.greenBright('Tests passed'));
42
34
  }
43
- console.log(`Done in ${chalk.gray(((Date.now() - __classPrivateFieldGet(this, _FilesReporter_startTime, "f")) / 1000).toFixed(2) + 's')}`
35
+ console.log(`Done in ${chalk.gray(((Date.now() - this.#startTime) / 1000).toFixed(2) + 's')}`
44
36
  + `, passed ${chalk.greenBright(this.passed)} files`
45
37
  + (this.skipped ? `, skipped ${chalk[this.skipped ? 'yellowBright' : 'gray'](this.skipped)} cases` : '')
46
38
  + (this.failed ? `, failed ${chalk[this.failed ? 'redBright' : 'gray'](this.failed)} files` : ''));
47
39
  return this.failed === 0;
48
40
  }
49
41
  }
50
- _FilesReporter_startTime = new WeakMap();
@@ -1,17 +1,17 @@
1
1
  import chalk from 'chalk';
2
2
  import { absToRel } from '../utils.js';
3
3
  export class SilentReporter {
4
+ total = 0;
5
+ passed = 0;
6
+ failed = 0;
7
+ skipped = 0;
8
+ passedFiles = 0;
9
+ failedFiles = 0;
10
+ passedNamesFlat = [];
11
+ flushOnError = true;
12
+ errorOutput = '';
13
+ onProgress = () => { };
4
14
  constructor(flushOnError = true, onProgress = () => { }) {
5
- this.total = 0;
6
- this.passed = 0;
7
- this.failed = 0;
8
- this.skipped = 0;
9
- this.passedFiles = 0;
10
- this.failedFiles = 0;
11
- this.passedNamesFlat = [];
12
- this.flushOnError = true;
13
- this.errorOutput = '';
14
- this.onProgress = () => { };
15
15
  this.flushOnError = flushOnError;
16
16
  this.onProgress = onProgress;
17
17
  }