ic-mops 0.7.4 → 0.8.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/cli.js +11 -2
- package/commands/sources.js +1 -1
- package/commands/template.js +28 -0
- package/commands/test.js +13 -7
- package/package.json +1 -1
- package/templates/mops-test.yml +29 -0
package/cli.js
CHANGED
|
@@ -16,6 +16,7 @@ import {search} from './commands/search.js';
|
|
|
16
16
|
import {add} from './commands/add.js';
|
|
17
17
|
import {cacheSize, cleanCache} from './cache.js';
|
|
18
18
|
import {test} from './commands/test.js';
|
|
19
|
+
import {template} from './commands/template.js';
|
|
19
20
|
// import {upgrade} from './commands/upgrade.js';
|
|
20
21
|
|
|
21
22
|
let cwd = process.cwd();
|
|
@@ -155,11 +156,19 @@ program
|
|
|
155
156
|
|
|
156
157
|
// test
|
|
157
158
|
program
|
|
158
|
-
.command('test')
|
|
159
|
+
.command('test [filter]')
|
|
159
160
|
.description('Run tests')
|
|
160
161
|
.option('--watch', 'Enable watch mode')
|
|
162
|
+
.action(async (filter, options) => {
|
|
163
|
+
await test(filter, options);
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
// template
|
|
167
|
+
program
|
|
168
|
+
.command('template')
|
|
169
|
+
.description('Apply template')
|
|
161
170
|
.action(async (options) => {
|
|
162
|
-
await
|
|
171
|
+
await template(options);
|
|
163
172
|
});
|
|
164
173
|
|
|
165
174
|
// // upgrade
|
package/commands/sources.js
CHANGED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import chalk from 'chalk';
|
|
4
|
+
import prompts from 'prompts';
|
|
5
|
+
|
|
6
|
+
export async function template() {
|
|
7
|
+
let res = await prompts({
|
|
8
|
+
type: 'select',
|
|
9
|
+
name: 'value',
|
|
10
|
+
message: 'Select template:',
|
|
11
|
+
choices: [
|
|
12
|
+
{title: 'GitHub Workflow to run \'mops test\'', value: 'github-workflow:mops-test'},
|
|
13
|
+
{title: '× Cancel', value: ''},
|
|
14
|
+
],
|
|
15
|
+
initial: 0,
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
if (res.value === 'github-workflow:mops-test') {
|
|
19
|
+
let dest = path.resolve(process.cwd(), '.github/workflows/mops-test.yml');
|
|
20
|
+
if (fs.existsSync(dest)) {
|
|
21
|
+
console.log(chalk.yellow('Workflow already exists:'), dest);
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
let mopsTestYml = new URL('../templates/mops-test.yml', import.meta.url);
|
|
25
|
+
fs.copyFileSync(mopsTestYml, dest);
|
|
26
|
+
console.log(chalk.green('Workflow created:'), dest);
|
|
27
|
+
}
|
|
28
|
+
}
|
package/commands/test.js
CHANGED
|
@@ -18,14 +18,14 @@ let globConfig = {
|
|
|
18
18
|
ignore: ignore,
|
|
19
19
|
};
|
|
20
20
|
|
|
21
|
-
export async function test({watch = false} = {}) {
|
|
21
|
+
export async function test(filter = '', {watch = false} = {}) {
|
|
22
22
|
if (watch) {
|
|
23
23
|
// todo: run only changed for *.test.mo?
|
|
24
24
|
// todo: run all for *.mo?
|
|
25
25
|
let run = debounce(async () => {
|
|
26
26
|
console.clear();
|
|
27
27
|
process.stdout.write('\x1Bc');
|
|
28
|
-
await runAll();
|
|
28
|
+
await runAll(filter);
|
|
29
29
|
console.log('-'.repeat(50));
|
|
30
30
|
console.log('Waiting for file changes...');
|
|
31
31
|
console.log(chalk.gray((`Press ${chalk.gray('Ctrl+C')} to exit.`)));
|
|
@@ -42,7 +42,7 @@ export async function test({watch = false} = {}) {
|
|
|
42
42
|
run();
|
|
43
43
|
}
|
|
44
44
|
else {
|
|
45
|
-
let passed = await runAll();
|
|
45
|
+
let passed = await runAll(filter);
|
|
46
46
|
if (!passed) {
|
|
47
47
|
process.exit(1);
|
|
48
48
|
}
|
|
@@ -51,7 +51,7 @@ export async function test({watch = false} = {}) {
|
|
|
51
51
|
|
|
52
52
|
let dfxCache;
|
|
53
53
|
|
|
54
|
-
export async function runAll() {
|
|
54
|
+
export async function runAll(filter = '') {
|
|
55
55
|
let start = Date.now();
|
|
56
56
|
|
|
57
57
|
let files = [];
|
|
@@ -60,7 +60,11 @@ export async function runAll() {
|
|
|
60
60
|
files = [libFiles[0]];
|
|
61
61
|
}
|
|
62
62
|
else {
|
|
63
|
-
|
|
63
|
+
let globStr = '**/test?(s)/**/*.test.mo';
|
|
64
|
+
if (filter) {
|
|
65
|
+
globStr = `**/test?(s)/**/*${filter}*`;
|
|
66
|
+
}
|
|
67
|
+
files = glob.sync(globStr, globConfig);
|
|
64
68
|
}
|
|
65
69
|
if (!files.length) {
|
|
66
70
|
console.log('No test files found');
|
|
@@ -72,7 +76,7 @@ export async function runAll() {
|
|
|
72
76
|
for (let file of files) {
|
|
73
77
|
console.log(chalk.gray(`• ${file}`));
|
|
74
78
|
}
|
|
75
|
-
console.log('
|
|
79
|
+
console.log('='.repeat(50));
|
|
76
80
|
|
|
77
81
|
let failed = 0;
|
|
78
82
|
let passed = 0;
|
|
@@ -86,6 +90,7 @@ export async function runAll() {
|
|
|
86
90
|
let mmf1 = new MMF1;
|
|
87
91
|
|
|
88
92
|
await new Promise((resolve) => {
|
|
93
|
+
file !== files[0] && console.log('-'.repeat(50));
|
|
89
94
|
console.log(`Running ${chalk.gray(file)}`);
|
|
90
95
|
|
|
91
96
|
let proc = spawn(`${dfxCache}/moc`, ['-r', '-wasi-system-api', '-ref-system-api', '--hide-warnings', '--error-detail=2', ...sourcesArr.join(' ').split(' '), file]);
|
|
@@ -123,7 +128,8 @@ export async function runAll() {
|
|
|
123
128
|
failed += mmf1.failed;
|
|
124
129
|
skipped += mmf1.skipped;
|
|
125
130
|
}
|
|
126
|
-
|
|
131
|
+
|
|
132
|
+
console.log('='.repeat(50));
|
|
127
133
|
if (failed) {
|
|
128
134
|
console.log(chalk.redBright('Tests failed'));
|
|
129
135
|
}
|
package/package.json
CHANGED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
name: mops test
|
|
2
|
+
|
|
3
|
+
on: [push, pull_request]
|
|
4
|
+
|
|
5
|
+
jobs:
|
|
6
|
+
test:
|
|
7
|
+
runs-on: ubuntu-latest
|
|
8
|
+
|
|
9
|
+
steps:
|
|
10
|
+
- uses: actions/checkout@v3
|
|
11
|
+
- uses: actions/setup-node@v3
|
|
12
|
+
with:
|
|
13
|
+
node-version: 18
|
|
14
|
+
- uses: aviate-labs/setup-dfx@v0.2.3
|
|
15
|
+
with:
|
|
16
|
+
vessel-version: 0.6.3
|
|
17
|
+
dfx-version: 0.13.0
|
|
18
|
+
|
|
19
|
+
- name: install dfx
|
|
20
|
+
run: dfx cache install
|
|
21
|
+
|
|
22
|
+
- name: install mops
|
|
23
|
+
run: npm i ic-mops -g --yes
|
|
24
|
+
|
|
25
|
+
- name: install mops packages
|
|
26
|
+
run: mops install
|
|
27
|
+
|
|
28
|
+
- name: run tests
|
|
29
|
+
run: mops test
|