ic-mops 0.45.3 → 1.0.0-pre.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/.eslintrc.json +0 -0
- package/.gitignore +0 -0
- package/CHANGELOG.md +15 -0
- package/README.md +1 -1
- package/api/actors.ts +25 -17
- package/api/downloadPackageFiles.ts +0 -0
- package/api/getHighestVersion.ts +0 -0
- package/api/index.ts +0 -0
- package/api/network.ts +0 -0
- package/api/resolveVersion.ts +0 -0
- package/cache.ts +20 -8
- package/cli.ts +28 -27
- package/commands/add.ts +4 -0
- package/commands/bench/bench-canister.mo +34 -8
- package/commands/bench/user-bench.mo +0 -0
- package/commands/bench-replica.ts +11 -6
- package/commands/bench.ts +31 -5
- package/commands/bump.ts +0 -0
- package/commands/docs.ts +0 -0
- package/commands/outdated.ts +0 -0
- package/commands/publish.ts +1 -1
- package/commands/replica.ts +237 -0
- package/commands/search.ts +0 -0
- package/commands/sources.ts +2 -3
- package/commands/sync.ts +0 -0
- package/commands/template.ts +0 -0
- package/commands/test/mmf1.ts +5 -5
- package/commands/test/reporters/compact-reporter.ts +2 -1
- package/commands/test/reporters/files-reporter.ts +3 -2
- package/commands/test/reporters/reporter.ts +2 -1
- package/commands/test/reporters/silent-reporter.ts +2 -1
- package/commands/test/reporters/verbose-reporter.ts +14 -4
- package/commands/test/test.ts +213 -74
- package/commands/test/utils.ts +0 -0
- package/commands/toolchain/moc.ts +0 -0
- package/commands/toolchain/pocket-ic.ts +0 -0
- package/commands/toolchain/toolchain-utils.ts +0 -0
- package/commands/toolchain/wasmtime.ts +0 -0
- package/commands/transfer-ownership.ts +0 -0
- package/commands/update.ts +0 -0
- package/commands/user.ts +71 -1
- package/declarations/bench/bench.did +8 -4
- package/declarations/bench/bench.did.d.ts +4 -0
- package/declarations/bench/bench.did.js +4 -0
- package/declarations/storage/index.d.ts +0 -0
- package/declarations/storage/index.js +0 -0
- package/declarations/storage/storage.did +0 -0
- package/declarations/storage/storage.did.d.ts +0 -0
- package/declarations/storage/storage.did.js +0 -0
- package/dist/api/actors.js +19 -13
- package/dist/cache.js +17 -8
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +24 -27
- package/dist/commands/add.js +3 -0
- package/dist/commands/bench/bench-canister.mo +34 -8
- package/dist/commands/bench/user-bench.mo +0 -0
- package/dist/commands/bench-replica.d.ts +2 -1
- package/dist/commands/bench-replica.js +10 -6
- package/dist/commands/bench.js +29 -5
- package/dist/commands/publish.js +1 -1
- package/dist/commands/replica.d.ts +59 -0
- package/dist/commands/replica.js +193 -0
- package/dist/commands/sources.d.ts +2 -2
- package/dist/commands/sources.js +2 -3
- package/dist/commands/test/mmf1.d.ts +2 -2
- package/dist/commands/test/mmf1.js +4 -4
- package/dist/commands/test/reporters/compact-reporter.d.ts +2 -1
- package/dist/commands/test/reporters/compact-reporter.js +1 -1
- package/dist/commands/test/reporters/files-reporter.d.ts +2 -1
- package/dist/commands/test/reporters/files-reporter.js +2 -2
- package/dist/commands/test/reporters/reporter.d.ts +2 -1
- package/dist/commands/test/reporters/silent-reporter.d.ts +2 -1
- package/dist/commands/test/reporters/silent-reporter.js +1 -1
- package/dist/commands/test/reporters/verbose-reporter.d.ts +3 -1
- package/dist/commands/test/reporters/verbose-reporter.js +12 -4
- package/dist/commands/test/test.d.ts +10 -8
- package/dist/commands/test/test.js +170 -71
- package/dist/commands/user.d.ts +6 -0
- package/dist/commands/user.js +59 -1
- package/dist/declarations/bench/bench.did +8 -4
- package/dist/declarations/bench/bench.did.d.ts +4 -0
- package/dist/declarations/bench/bench.did.js +4 -0
- package/dist/declarations/storage/index.d.ts +0 -0
- package/dist/declarations/storage/index.js +0 -0
- package/dist/declarations/storage/storage.did +0 -0
- package/dist/declarations/storage/storage.did.d.ts +0 -0
- package/dist/declarations/storage/storage.did.js +0 -0
- package/dist/mops.d.ts +1 -1
- package/dist/mops.js +4 -28
- package/dist/package.json +4 -3
- package/dist/resolve-packages.d.ts +2 -2
- package/dist/resolve-packages.js +29 -7
- package/dist/templates/README.md +0 -0
- package/dist/templates/licenses/Apache-2.0 +0 -0
- package/dist/templates/licenses/Apache-2.0-NOTICE +0 -0
- package/dist/templates/licenses/MIT +0 -0
- package/dist/templates/mops-publish.yml +0 -0
- package/dist/templates/mops-test.yml +0 -0
- package/dist/templates/src/lib.mo +0 -0
- package/dist/templates/test/lib.test.mo +0 -0
- package/dist/types.d.ts +1 -0
- package/global.d.ts +0 -0
- package/helpers/get-dfx-version.ts +0 -0
- package/helpers/get-moc-path.ts +0 -0
- package/helpers/get-moc-version.ts +0 -0
- package/mops.ts +4 -31
- package/package.json +4 -3
- package/parallel.ts +0 -0
- package/resolve-packages.ts +39 -8
- package/templates/README.md +0 -0
- package/templates/licenses/Apache-2.0 +0 -0
- package/templates/licenses/Apache-2.0-NOTICE +0 -0
- package/templates/licenses/MIT +0 -0
- package/templates/mops-publish.yml +0 -0
- package/templates/mops-test.yml +0 -0
- package/templates/src/lib.mo +0 -0
- package/templates/test/lib.test.mo +0 -0
- package/types.ts +3 -1
- package/.DS_Store +0 -0
- package/bundle/bench/bench-canister.mo +0 -87
- package/bundle/bench/user-bench.mo +0 -14
- package/bundle/bin/moc-wrapper.sh +0 -40
- package/bundle/bin/mops.js +0 -3
- package/bundle/cli.js +0 -163
- package/bundle/cli.tgz +0 -0
- package/bundle/declarations/bench/bench.did +0 -26
- package/bundle/declarations/bench/bench.did.d.ts +0 -29
- package/bundle/declarations/bench/bench.did.js +0 -26
- package/bundle/declarations/bench/index.d.ts +0 -50
- package/bundle/declarations/bench/index.js +0 -40
- package/bundle/declarations/main/index.d.ts +0 -50
- package/bundle/declarations/main/index.js +0 -40
- package/bundle/declarations/main/main.did +0 -438
- package/bundle/declarations/main/main.did.d.ts +0 -360
- package/bundle/declarations/main/main.did.js +0 -412
- package/bundle/declarations/storage/index.d.ts +0 -50
- package/bundle/declarations/storage/index.js +0 -30
- package/bundle/declarations/storage/storage.did +0 -46
- package/bundle/declarations/storage/storage.did.d.ts +0 -40
- package/bundle/declarations/storage/storage.did.js +0 -38
- package/bundle/package.json +0 -31
- package/bundle/templates/README.md +0 -13
- package/bundle/templates/licenses/Apache-2.0 +0 -202
- package/bundle/templates/licenses/Apache-2.0-NOTICE +0 -13
- package/bundle/templates/licenses/MIT +0 -21
- package/bundle/templates/mops-publish.yml +0 -17
- package/bundle/templates/mops-test.yml +0 -22
- package/bundle/templates/src/lib.mo +0 -15
- package/bundle/templates/test/lib.test.mo +0 -4
- package/commands/import-identity.ts +0 -62
- package/commands/whoami.ts +0 -12
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
import process from 'node:process';
|
|
2
|
+
import {ChildProcessWithoutNullStreams, execSync, spawn} from 'node:child_process';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import fs from 'node:fs';
|
|
5
|
+
import {PassThrough} from 'node:stream';
|
|
6
|
+
|
|
7
|
+
import {IDL} from '@dfinity/candid';
|
|
8
|
+
import {Actor, HttpAgent} from '@dfinity/agent';
|
|
9
|
+
import {PocketIc, PocketIcServer} from 'pic-ic';
|
|
10
|
+
|
|
11
|
+
import {readConfig} from '../mops.js';
|
|
12
|
+
import {toolchain} from './toolchain/index.js';
|
|
13
|
+
|
|
14
|
+
type StartOptions = {
|
|
15
|
+
type ?: 'dfx' | 'pocket-ic';
|
|
16
|
+
dir ?: string;
|
|
17
|
+
verbose ?: boolean;
|
|
18
|
+
silent ?: boolean;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export class Replica {
|
|
22
|
+
type : 'dfx' | 'pocket-ic' = 'dfx';
|
|
23
|
+
verbose = false;
|
|
24
|
+
canisters : Record<string, {cwd : string; canisterId : string; actor : any; stream : PassThrough;}> = {};
|
|
25
|
+
pocketIcServer ?: PocketIcServer;
|
|
26
|
+
pocketIc ?: PocketIc;
|
|
27
|
+
dfxProcess ?: ChildProcessWithoutNullStreams;
|
|
28
|
+
dir : string = ''; // absolute path (/.../.mops/.test/)
|
|
29
|
+
ttl = 60;
|
|
30
|
+
|
|
31
|
+
async start({type, dir, verbose, silent} : StartOptions = {}) {
|
|
32
|
+
this.type = type ?? this.type;
|
|
33
|
+
this.verbose = verbose ?? this.verbose;
|
|
34
|
+
this.dir = dir ?? this.dir;
|
|
35
|
+
|
|
36
|
+
silent || console.log(`Starting ${this.type} replica...`);
|
|
37
|
+
|
|
38
|
+
if (this.type == 'dfx') {
|
|
39
|
+
fs.mkdirSync(this.dir, {recursive: true});
|
|
40
|
+
fs.writeFileSync(path.join(this.dir, 'dfx.json'), JSON.stringify(this.dfxJson(''), null, 2));
|
|
41
|
+
fs.writeFileSync(path.join(this.dir, 'canister.did'), 'service : { runTests: () -> (); }');
|
|
42
|
+
|
|
43
|
+
await this.stop();
|
|
44
|
+
|
|
45
|
+
this.dfxProcess = spawn('dfx', ['start', '--clean', '--artificial-delay', '0', (this.verbose ? '' : '-qqqq')].filter(x => x), {cwd: this.dir});
|
|
46
|
+
|
|
47
|
+
// process canister logs
|
|
48
|
+
this._attachCanisterLogHandler(this.dfxProcess);
|
|
49
|
+
|
|
50
|
+
this.dfxProcess.stdout.on('data', (data) => {
|
|
51
|
+
console.log('DFX:', data.toString());
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
// await for dfx to start
|
|
55
|
+
let ok = false;
|
|
56
|
+
while (!ok) {
|
|
57
|
+
await fetch('http://127.0.0.1:4945/api/v2/status')
|
|
58
|
+
.then(res => {
|
|
59
|
+
if (res.status === 200) {
|
|
60
|
+
ok = true;
|
|
61
|
+
}
|
|
62
|
+
})
|
|
63
|
+
.catch(() => {})
|
|
64
|
+
.finally(() => {
|
|
65
|
+
return new Promise(resolve => setTimeout(resolve, 1000));
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
let pocketIcBin = await toolchain.bin('pocket-ic');
|
|
71
|
+
|
|
72
|
+
// eslint-disable-next-line
|
|
73
|
+
let config = readConfig();
|
|
74
|
+
if (config.toolchain?.['pocket-ic'] !== '4.0.0') {
|
|
75
|
+
console.error('Current Mops CLI only supports pocket-ic 4.0.0');
|
|
76
|
+
process.exit(1);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
this.pocketIcServer = await PocketIcServer.start({
|
|
80
|
+
showRuntimeLogs: false,
|
|
81
|
+
showCanisterLogs: false,
|
|
82
|
+
binPath: pocketIcBin,
|
|
83
|
+
ttl: this.ttl,
|
|
84
|
+
});
|
|
85
|
+
this.pocketIc = await PocketIc.create(this.pocketIcServer.getUrl());
|
|
86
|
+
|
|
87
|
+
// process canister logs
|
|
88
|
+
this._attachCanisterLogHandler(this.pocketIcServer.serverProcess as ChildProcessWithoutNullStreams);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
_attachCanisterLogHandler(proc : ChildProcessWithoutNullStreams) {
|
|
93
|
+
let curData = '';
|
|
94
|
+
proc.stderr.on('data', (data) => {
|
|
95
|
+
curData = curData + data.toString();
|
|
96
|
+
|
|
97
|
+
if (curData.includes('\n')) {
|
|
98
|
+
let m = curData.match(/\[Canister ([a-z0-9-]+)\] (.*)/);
|
|
99
|
+
if (!m) {
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
let [, canisterId, msg] = m;
|
|
103
|
+
|
|
104
|
+
let stream = this.getCanisterStream(canisterId || '');
|
|
105
|
+
if (stream) {
|
|
106
|
+
stream.write(msg);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
curData = '';
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
async stop(sigint = false) {
|
|
115
|
+
if (this.type == 'dfx') {
|
|
116
|
+
this.dfxProcess?.kill();
|
|
117
|
+
// execSync('dfx stop' + (this.verbose ? '' : ' -qqqq'), {cwd: this.dir, timeout: 10_000, stdio: ['pipe', this.verbose ? 'inherit' : 'ignore', 'pipe']});
|
|
118
|
+
}
|
|
119
|
+
else if (this.pocketIc && this.pocketIcServer) {
|
|
120
|
+
if (!sigint) {
|
|
121
|
+
await this.pocketIc.tearDown(); // error 'fetch failed' if run on SIGINT
|
|
122
|
+
}
|
|
123
|
+
await this.pocketIcServer.stop();
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
async deploy(name : string, wasm : string, idlFactory : IDL.InterfaceFactory, cwd : string = process.cwd()) {
|
|
128
|
+
if (this.type === 'dfx') {
|
|
129
|
+
// prepare dfx.json for current canister
|
|
130
|
+
let dfxJson = path.join(this.dir, 'dfx.json');
|
|
131
|
+
|
|
132
|
+
let oldDfxJsonData;
|
|
133
|
+
if (fs.existsSync(dfxJson)) {
|
|
134
|
+
oldDfxJsonData = JSON.parse(fs.readFileSync(dfxJson).toString());
|
|
135
|
+
}
|
|
136
|
+
let newDfxJsonData = this.dfxJson(name, name + '.wasm');
|
|
137
|
+
|
|
138
|
+
if (oldDfxJsonData.canisters) {
|
|
139
|
+
newDfxJsonData.canisters = Object.assign(oldDfxJsonData.canisters, newDfxJsonData.canisters);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
fs.mkdirSync(this.dir, {recursive: true});
|
|
143
|
+
fs.writeFileSync(dfxJson, JSON.stringify(newDfxJsonData, null, 2));
|
|
144
|
+
|
|
145
|
+
execSync(`dfx deploy ${name} --mode reinstall --yes --identity anonymous`, {cwd: this.dir, stdio: this.verbose ? 'pipe' : ['pipe', 'ignore', 'pipe']});
|
|
146
|
+
execSync(`dfx ledger fabricate-cycles --canister ${name} --t 100`, {cwd: this.dir, stdio: this.verbose ? 'pipe' : ['pipe', 'ignore', 'pipe']});
|
|
147
|
+
|
|
148
|
+
let canisterId = execSync(`dfx canister id ${name}`, {cwd: this.dir}).toString().trim();
|
|
149
|
+
|
|
150
|
+
let actor = Actor.createActor(idlFactory, {
|
|
151
|
+
agent: await HttpAgent.create({
|
|
152
|
+
host: 'http://127.0.0.1:4945',
|
|
153
|
+
shouldFetchRootKey: true,
|
|
154
|
+
}),
|
|
155
|
+
canisterId,
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
this.canisters[name] = {
|
|
159
|
+
cwd,
|
|
160
|
+
canisterId,
|
|
161
|
+
actor,
|
|
162
|
+
stream: new PassThrough(),
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
else if (this.pocketIc) {
|
|
166
|
+
// let {canisterId, actor} = await this.pocketIc.setupCanister(idlFactory, wasm);
|
|
167
|
+
let {canisterId, actor} = await this.pocketIc.setupCanister({
|
|
168
|
+
idlFactory,
|
|
169
|
+
wasm,
|
|
170
|
+
});
|
|
171
|
+
await this.pocketIc.addCycles(canisterId, 1_000_000_000_000);
|
|
172
|
+
this.canisters[name] = {
|
|
173
|
+
cwd,
|
|
174
|
+
canisterId: canisterId.toText(),
|
|
175
|
+
actor,
|
|
176
|
+
stream: new PassThrough(),
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
if (!this.canisters[name]) {
|
|
181
|
+
throw new Error(`Canister ${name} not found`);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
return this.canisters[name];
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
getActor(name : string) : unknown {
|
|
188
|
+
if (!this.canisters[name]) {
|
|
189
|
+
throw new Error(`Canister ${name} not found`);
|
|
190
|
+
}
|
|
191
|
+
return this.canisters[name]?.actor;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
getCanister(name : string) {
|
|
195
|
+
return this.canisters[name];
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
getCanisterId(name : string) : string {
|
|
199
|
+
return this.canisters[name]?.canisterId || '';
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
getCanisterStream(canisterId : string) : PassThrough | null {
|
|
203
|
+
for (let canister of Object.values(this.canisters)) {
|
|
204
|
+
if (canister.canisterId === canisterId) {
|
|
205
|
+
return canister.stream;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
return null;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
dfxJson(canisterName : string, wasmPath = 'canister.wasm', didPath = 'canister.did') {
|
|
212
|
+
let canisters : Record<string, any> = {};
|
|
213
|
+
if (canisterName) {
|
|
214
|
+
canisters[canisterName] = {
|
|
215
|
+
type: 'custom',
|
|
216
|
+
wasm: wasmPath,
|
|
217
|
+
candid: didPath,
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
return {
|
|
222
|
+
version: 1,
|
|
223
|
+
canisters,
|
|
224
|
+
defaults: {
|
|
225
|
+
build: {
|
|
226
|
+
packtool: 'mops sources',
|
|
227
|
+
},
|
|
228
|
+
},
|
|
229
|
+
networks: {
|
|
230
|
+
local: {
|
|
231
|
+
type: 'ephemeral',
|
|
232
|
+
bind: '127.0.0.1:4945',
|
|
233
|
+
},
|
|
234
|
+
},
|
|
235
|
+
};
|
|
236
|
+
}
|
|
237
|
+
}
|
package/commands/search.ts
CHANGED
|
File without changes
|
package/commands/sources.ts
CHANGED
|
@@ -4,13 +4,12 @@ import fs from 'node:fs';
|
|
|
4
4
|
import {checkConfigFile, formatDir, formatGithubDir, getDependencyType, readConfig} from '../mops.js';
|
|
5
5
|
import {resolvePackages} from '../resolve-packages.js';
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
export async function sources({verbose = false, cwd = process.cwd()} = {}) {
|
|
7
|
+
export async function sources({conflicts = 'ignore' as 'warning' | 'error' | 'ignore', cwd = process.cwd()} = {}) {
|
|
9
8
|
if (!checkConfigFile()) {
|
|
10
9
|
return [];
|
|
11
10
|
}
|
|
12
11
|
|
|
13
|
-
let resolvedPackages = await resolvePackages({
|
|
12
|
+
let resolvedPackages = await resolvePackages({conflicts});
|
|
14
13
|
|
|
15
14
|
// sources
|
|
16
15
|
return Object.entries(resolvedPackages).map(([name, version]) => {
|
package/commands/sync.ts
CHANGED
|
File without changes
|
package/commands/template.ts
CHANGED
|
File without changes
|
package/commands/test/mmf1.ts
CHANGED
|
@@ -15,7 +15,7 @@ export class MMF1 {
|
|
|
15
15
|
failed = 0;
|
|
16
16
|
passed = 0;
|
|
17
17
|
skipped = 0;
|
|
18
|
-
|
|
18
|
+
strategy : Strategy;
|
|
19
19
|
output : {
|
|
20
20
|
type : MessageType;
|
|
21
21
|
message : string;
|
|
@@ -27,19 +27,19 @@ export class MMF1 {
|
|
|
27
27
|
// or <file> › <suite> › <test> › <nested-test>...
|
|
28
28
|
passedNamesFlat : string[] = [];
|
|
29
29
|
|
|
30
|
-
constructor(
|
|
31
|
-
this.
|
|
30
|
+
constructor(strategy : Strategy, file : string) {
|
|
31
|
+
this.strategy = strategy;
|
|
32
32
|
this.file = file;
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
_log(type : MessageType, ...args : string[]) {
|
|
36
|
-
if (this.
|
|
36
|
+
if (this.strategy === 'store') {
|
|
37
37
|
this.output.push({
|
|
38
38
|
type,
|
|
39
39
|
message: args.join(' '),
|
|
40
40
|
});
|
|
41
41
|
}
|
|
42
|
-
else if (this.
|
|
42
|
+
else if (this.strategy === 'print') {
|
|
43
43
|
console.log(...args);
|
|
44
44
|
}
|
|
45
45
|
}
|
|
@@ -3,6 +3,7 @@ import logUpdate from 'log-update';
|
|
|
3
3
|
import {absToRel} from '../utils.js';
|
|
4
4
|
import {MMF1} from '../mmf1.js';
|
|
5
5
|
import {Reporter} from './reporter.js';
|
|
6
|
+
import {TestMode} from '../../../types.js';
|
|
6
7
|
|
|
7
8
|
export class CompactReporter implements Reporter {
|
|
8
9
|
passed = 0;
|
|
@@ -23,7 +24,7 @@ export class CompactReporter implements Reporter {
|
|
|
23
24
|
this.#startTimer();
|
|
24
25
|
}
|
|
25
26
|
|
|
26
|
-
addRun(file : string, mmf : MMF1, state : Promise<void>,
|
|
27
|
+
addRun(file : string, mmf : MMF1, state : Promise<void>, _mode : TestMode) {
|
|
27
28
|
this.#runningFiles.add(file);
|
|
28
29
|
this.#log();
|
|
29
30
|
|
|
@@ -2,6 +2,7 @@ import chalk from 'chalk';
|
|
|
2
2
|
import {absToRel} from '../utils.js';
|
|
3
3
|
import {MMF1} from '../mmf1.js';
|
|
4
4
|
import {Reporter} from './reporter.js';
|
|
5
|
+
import {TestMode} from '../../../types.js';
|
|
5
6
|
|
|
6
7
|
export class FilesReporter implements Reporter {
|
|
7
8
|
passed = 0;
|
|
@@ -15,7 +16,7 @@ export class FilesReporter implements Reporter {
|
|
|
15
16
|
console.log('='.repeat(50));
|
|
16
17
|
}
|
|
17
18
|
|
|
18
|
-
addRun(file : string, mmf : MMF1, state : Promise<void>,
|
|
19
|
+
addRun(file : string, mmf : MMF1, state : Promise<void>, mode : TestMode) {
|
|
19
20
|
state.then(() => {
|
|
20
21
|
this.passed += Number(mmf.failed === 0);
|
|
21
22
|
this.failed += Number(mmf.failed !== 0);
|
|
@@ -27,7 +28,7 @@ export class FilesReporter implements Reporter {
|
|
|
27
28
|
console.log('-'.repeat(50));
|
|
28
29
|
}
|
|
29
30
|
else {
|
|
30
|
-
console.log(`${chalk.green('✓')} ${absToRel(file)} ${
|
|
31
|
+
console.log(`${chalk.green('✓')} ${absToRel(file)} ${mode === 'interpreter' ? '' : chalk.gray(`(${mode})`)}`);
|
|
31
32
|
}
|
|
32
33
|
});
|
|
33
34
|
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
import {TestMode} from '../../../types.js';
|
|
1
2
|
import {MMF1} from '../mmf1.js';
|
|
2
3
|
|
|
3
4
|
export interface Reporter {
|
|
4
5
|
addFiles(files : string[]) : void;
|
|
5
|
-
addRun(file : string, mmf : MMF1, state : Promise<void>,
|
|
6
|
+
addRun(file : string, mmf : MMF1, state : Promise<void>, mode : TestMode, progressive ?: boolean) : void;
|
|
6
7
|
done() : boolean;
|
|
7
8
|
}
|
|
@@ -2,6 +2,7 @@ import chalk from 'chalk';
|
|
|
2
2
|
import {absToRel} from '../utils.js';
|
|
3
3
|
import {MMF1} from '../mmf1.js';
|
|
4
4
|
import {Reporter} from './reporter.js';
|
|
5
|
+
import {TestMode} from '../../../types.js';
|
|
5
6
|
|
|
6
7
|
export class SilentReporter implements Reporter {
|
|
7
8
|
passed = 0;
|
|
@@ -13,7 +14,7 @@ export class SilentReporter implements Reporter {
|
|
|
13
14
|
|
|
14
15
|
addFiles(_files : string[]) {}
|
|
15
16
|
|
|
16
|
-
addRun(file : string, mmf : MMF1, state : Promise<void>,
|
|
17
|
+
addRun(file : string, mmf : MMF1, state : Promise<void>, _mode : TestMode) {
|
|
17
18
|
state.then(() => {
|
|
18
19
|
this.passed += mmf.passed;
|
|
19
20
|
this.failed += mmf.failed;
|
|
@@ -2,6 +2,7 @@ import chalk from 'chalk';
|
|
|
2
2
|
import {absToRel} from '../utils.js';
|
|
3
3
|
import {MMF1} from '../mmf1.js';
|
|
4
4
|
import {Reporter} from './reporter.js';
|
|
5
|
+
import {TestMode} from '../../../types.js';
|
|
5
6
|
|
|
6
7
|
export class VerboseReporter implements Reporter {
|
|
7
8
|
passed = 0;
|
|
@@ -19,7 +20,11 @@ export class VerboseReporter implements Reporter {
|
|
|
19
20
|
console.log('='.repeat(50));
|
|
20
21
|
}
|
|
21
22
|
|
|
22
|
-
addRun(file : string, mmf : MMF1, state : Promise<void>,
|
|
23
|
+
addRun(file : string, mmf : MMF1, state : Promise<void>, mode : TestMode, progressive = false) {
|
|
24
|
+
if (progressive) {
|
|
25
|
+
this._printStart(file, mode);
|
|
26
|
+
}
|
|
27
|
+
|
|
23
28
|
state.then(() => {
|
|
24
29
|
this.passed += mmf.passed;
|
|
25
30
|
this.failed += mmf.failed;
|
|
@@ -28,9 +33,9 @@ export class VerboseReporter implements Reporter {
|
|
|
28
33
|
if (mmf.passed === 0 && mmf.failed === 0) {
|
|
29
34
|
this.passed++;
|
|
30
35
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
36
|
+
if (!progressive) {
|
|
37
|
+
this._printStart(file, mode);
|
|
38
|
+
}
|
|
34
39
|
mmf.flush();
|
|
35
40
|
});
|
|
36
41
|
}
|
|
@@ -52,4 +57,9 @@ export class VerboseReporter implements Reporter {
|
|
|
52
57
|
|
|
53
58
|
return this.failed === 0;
|
|
54
59
|
}
|
|
60
|
+
|
|
61
|
+
_printStart(file : string, mode : TestMode) {
|
|
62
|
+
this.#curFileIndex++ && console.log('-'.repeat(50));
|
|
63
|
+
console.log(`Running ${chalk.gray(absToRel(file))} ${mode === 'interpreter' ? '' : chalk.gray(`(${mode})`)}`);
|
|
64
|
+
}
|
|
55
65
|
}
|