@apollo-annotation/cli 1.1.0 → 1.1.2
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/README.md +133 -87
- package/dist/ApolloConf.d.ts.map +1 -1
- package/dist/ApolloConf.js +14 -3
- package/dist/ApolloConf.js.map +1 -1
- package/dist/baseCommand.d.ts +37 -1
- package/dist/baseCommand.d.ts.map +1 -1
- package/dist/baseCommand.js +226 -9
- package/dist/baseCommand.js.map +1 -1
- package/dist/commands/assembly/add-from-fasta.d.ts +8 -8
- package/dist/commands/assembly/add-from-fasta.d.ts.map +1 -1
- package/dist/commands/assembly/add-from-fasta.js +20 -16
- package/dist/commands/assembly/add-from-fasta.js.map +1 -1
- package/dist/commands/assembly/add-from-gff.d.ts +5 -5
- package/dist/commands/assembly/add-from-gff.d.ts.map +1 -1
- package/dist/commands/assembly/add-from-gff.js +2 -4
- package/dist/commands/assembly/add-from-gff.js.map +1 -1
- package/dist/commands/assembly/check.d.ts +3 -3
- package/dist/commands/assembly/check.d.ts.map +1 -1
- package/dist/commands/assembly/check.js +10 -48
- package/dist/commands/assembly/check.js.map +1 -1
- package/dist/commands/assembly/delete.d.ts +2 -2
- package/dist/commands/assembly/delete.d.ts.map +1 -1
- package/dist/commands/assembly/delete.js +4 -5
- package/dist/commands/assembly/delete.js.map +1 -1
- package/dist/commands/assembly/get.d.ts +1 -1
- package/dist/commands/assembly/get.d.ts.map +1 -1
- package/dist/commands/assembly/get.js +3 -5
- package/dist/commands/assembly/get.js.map +1 -1
- package/dist/commands/assembly/sequence.d.ts +4 -4
- package/dist/commands/assembly/sequence.d.ts.map +1 -1
- package/dist/commands/assembly/sequence.js +9 -29
- package/dist/commands/assembly/sequence.js.map +1 -1
- package/dist/commands/change/get.d.ts +1 -1
- package/dist/commands/change/get.d.ts.map +1 -1
- package/dist/commands/change/get.js +3 -5
- package/dist/commands/change/get.js.map +1 -1
- package/dist/commands/config.d.ts +4 -4
- package/dist/commands/config.d.ts.map +1 -1
- package/dist/commands/config.js +12 -19
- package/dist/commands/config.js.map +1 -1
- package/dist/commands/export/gff3.d.ts +2 -2
- package/dist/commands/export/gff3.d.ts.map +1 -1
- package/dist/commands/export/gff3.js +4 -26
- package/dist/commands/export/gff3.js.map +1 -1
- package/dist/commands/feature/add-child.d.ts +4 -4
- package/dist/commands/feature/add-child.d.ts.map +1 -1
- package/dist/commands/feature/add-child.js +6 -32
- package/dist/commands/feature/add-child.js.map +1 -1
- package/dist/commands/feature/add.d.ts +7 -18
- package/dist/commands/feature/add.d.ts.map +1 -1
- package/dist/commands/feature/add.js +4 -57
- package/dist/commands/feature/add.js.map +1 -1
- package/dist/commands/feature/check.d.ts +3 -2
- package/dist/commands/feature/check.d.ts.map +1 -1
- package/dist/commands/feature/check.js +16 -35
- package/dist/commands/feature/check.js.map +1 -1
- package/dist/commands/feature/copy.d.ts +4 -4
- package/dist/commands/feature/copy.d.ts.map +1 -1
- package/dist/commands/feature/copy.js +6 -32
- package/dist/commands/feature/copy.js.map +1 -1
- package/dist/commands/feature/delete.d.ts +4 -3
- package/dist/commands/feature/delete.d.ts.map +1 -1
- package/dist/commands/feature/delete.js +25 -46
- package/dist/commands/feature/delete.js.map +1 -1
- package/dist/commands/feature/edit-attribute.d.ts +4 -4
- package/dist/commands/feature/edit-attribute.d.ts.map +1 -1
- package/dist/commands/feature/edit-attribute.js +4 -24
- package/dist/commands/feature/edit-attribute.js.map +1 -1
- package/dist/commands/feature/edit-coords.d.ts +3 -3
- package/dist/commands/feature/edit-coords.d.ts.map +1 -1
- package/dist/commands/feature/edit-coords.js +4 -24
- package/dist/commands/feature/edit-coords.js.map +1 -1
- package/dist/commands/feature/edit-type.d.ts +2 -2
- package/dist/commands/feature/edit-type.d.ts.map +1 -1
- package/dist/commands/feature/edit-type.js +4 -24
- package/dist/commands/feature/edit-type.js.map +1 -1
- package/dist/commands/feature/edit.d.ts +1 -1
- package/dist/commands/feature/edit.d.ts.map +1 -1
- package/dist/commands/feature/edit.js +2 -18
- package/dist/commands/feature/edit.js.map +1 -1
- package/dist/commands/feature/get-id.d.ts +1 -1
- package/dist/commands/feature/get-id.d.ts.map +1 -1
- package/dist/commands/feature/get-id.js +5 -15
- package/dist/commands/feature/get-id.js.map +1 -1
- package/dist/commands/feature/get-indexed-id.d.ts +3 -3
- package/dist/commands/feature/get-indexed-id.d.ts.map +1 -1
- package/dist/commands/feature/get-indexed-id.js +3 -20
- package/dist/commands/feature/get-indexed-id.js.map +1 -1
- package/dist/commands/feature/get.d.ts +4 -4
- package/dist/commands/feature/get.d.ts.map +1 -1
- package/dist/commands/feature/get.js +4 -21
- package/dist/commands/feature/get.js.map +1 -1
- package/dist/commands/feature/import.d.ts +4 -4
- package/dist/commands/feature/import.d.ts.map +1 -1
- package/dist/commands/feature/import.js +4 -21
- package/dist/commands/feature/import.js.map +1 -1
- package/dist/commands/feature/search.d.ts +2 -2
- package/dist/commands/feature/search.d.ts.map +1 -1
- package/dist/commands/feature/search.js +9 -28
- package/dist/commands/feature/search.js.map +1 -1
- package/dist/commands/file/delete.d.ts +2 -1
- package/dist/commands/file/delete.d.ts.map +1 -1
- package/dist/commands/file/delete.js +12 -21
- package/dist/commands/file/delete.js.map +1 -1
- package/dist/commands/file/download.d.ts +2 -2
- package/dist/commands/file/download.d.ts.map +1 -1
- package/dist/commands/file/download.js +3 -7
- package/dist/commands/file/download.js.map +1 -1
- package/dist/commands/file/get.d.ts +1 -1
- package/dist/commands/file/get.d.ts.map +1 -1
- package/dist/commands/file/get.js +2 -4
- package/dist/commands/file/get.js.map +1 -1
- package/dist/commands/file/upload.d.ts +4 -4
- package/dist/commands/file/upload.d.ts.map +1 -1
- package/dist/commands/file/upload.js +3 -7
- package/dist/commands/file/upload.js.map +1 -1
- package/dist/commands/jbrowse/desktop.d.ts +4 -4
- package/dist/commands/jbrowse/get-config.d.ts.map +1 -1
- package/dist/commands/jbrowse/get-config.js +1 -7
- package/dist/commands/jbrowse/get-config.js.map +1 -1
- package/dist/commands/jbrowse/set-config.d.ts +1 -1
- package/dist/commands/jbrowse/set-config.d.ts.map +1 -1
- package/dist/commands/jbrowse/set-config.js +1 -19
- package/dist/commands/jbrowse/set-config.js.map +1 -1
- package/dist/commands/login.d.ts +5 -5
- package/dist/commands/login.d.ts.map +1 -1
- package/dist/commands/login.js +8 -7
- package/dist/commands/login.js.map +1 -1
- package/dist/commands/logout.d.ts.map +1 -1
- package/dist/commands/logout.js +2 -6
- package/dist/commands/logout.js.map +1 -1
- package/dist/commands/refseq/add-alias.d.ts +2 -2
- package/dist/commands/refseq/add-alias.d.ts.map +1 -1
- package/dist/commands/refseq/add-alias.js +2 -21
- package/dist/commands/refseq/add-alias.js.map +1 -1
- package/dist/commands/refseq/get.d.ts +1 -1
- package/dist/commands/refseq/get.d.ts.map +1 -1
- package/dist/commands/refseq/get.js +3 -5
- package/dist/commands/refseq/get.js.map +1 -1
- package/dist/commands/status.d.ts.map +1 -1
- package/dist/commands/status.js +2 -6
- package/dist/commands/status.js.map +1 -1
- package/dist/commands/user/get.d.ts +2 -2
- package/dist/commands/user/get.d.ts.map +1 -1
- package/dist/commands/user/get.js +1 -4
- package/dist/commands/user/get.js.map +1 -1
- package/dist/fileCommand.d.ts +2 -1
- package/dist/fileCommand.d.ts.map +1 -1
- package/dist/fileCommand.js +18 -11
- package/dist/fileCommand.js.map +1 -1
- package/dist/test/test.js +154 -30
- package/dist/test/test.js.map +1 -1
- package/dist/test/utils.d.ts.map +1 -1
- package/dist/test/utils.js +15 -2
- package/dist/test/utils.js.map +1 -1
- package/dist/utils.d.ts +1 -21
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +1 -234
- package/dist/utils.js.map +1 -1
- package/oclif.manifest.json +803 -515
- package/package.json +14 -15
package/dist/test/test.js
CHANGED
|
@@ -16,12 +16,13 @@
|
|
|
16
16
|
* yarn tsx --test-name-pattern='Print help|Feature get' src/test/test.ts
|
|
17
17
|
*/
|
|
18
18
|
import assert from 'node:assert';
|
|
19
|
+
import { spawn as spawnChildProcess } from 'node:child_process';
|
|
19
20
|
import * as crypto from 'node:crypto';
|
|
20
21
|
import fs from 'node:fs';
|
|
21
22
|
import { after, afterEach, before, beforeEach, describe } from 'node:test';
|
|
22
23
|
import { MongoClient } from 'mongodb';
|
|
23
24
|
import { Shell, deleteAllChecks } from './utils.js';
|
|
24
|
-
const apollo = 'yarn dev';
|
|
25
|
+
const apollo = process.env.APOLLO_BIN ?? 'yarn dev';
|
|
25
26
|
const P = '--profile testAdmin';
|
|
26
27
|
// let client = MongoClient
|
|
27
28
|
let client;
|
|
@@ -85,6 +86,82 @@ void describe('Test CLI', () => {
|
|
|
85
86
|
const p = new Shell(`${apollo} config ${P} accessType google`);
|
|
86
87
|
assert.strictEqual('', p.stdout.trim());
|
|
87
88
|
});
|
|
89
|
+
void globalThis.itName('Interactive login type select shows names, not raw objects', async () => {
|
|
90
|
+
// Regression test: /auth/types returns an array of
|
|
91
|
+
// {name, needsPopup, message} objects, but selectAccessType() in
|
|
92
|
+
// config.ts used to push those objects directly as a choice's `name`,
|
|
93
|
+
// so the interactive select rendered "[object Object]" instead of the
|
|
94
|
+
// login type name.
|
|
95
|
+
const serverScript = 'test_data/tmp_auth_types_server.mjs';
|
|
96
|
+
fs.writeFileSync(serverScript, `
|
|
97
|
+
import http from 'node:http'
|
|
98
|
+
const server = http.createServer((req, res) => {
|
|
99
|
+
if (req.url === '/auth/types') {
|
|
100
|
+
res.writeHead(200, { 'Content-Type': 'application/json' })
|
|
101
|
+
res.end(JSON.stringify([{ name: 'guest', needsPopup: false, message: 'Continue as Guest' }]))
|
|
102
|
+
return
|
|
103
|
+
}
|
|
104
|
+
res.writeHead(404)
|
|
105
|
+
res.end()
|
|
106
|
+
})
|
|
107
|
+
server.listen(0, () => {
|
|
108
|
+
console.log(server.address().port)
|
|
109
|
+
})
|
|
110
|
+
`);
|
|
111
|
+
const authServer = spawnChildProcess('node', [serverScript]);
|
|
112
|
+
const authPort = await new Promise((resolve) => {
|
|
113
|
+
authServer.stdout.once('data', (data) => {
|
|
114
|
+
resolve(data.toString().trim());
|
|
115
|
+
});
|
|
116
|
+
});
|
|
117
|
+
const child = spawnChildProcess(`${apollo} config ${P}`, {
|
|
118
|
+
shell: '/bin/bash',
|
|
119
|
+
});
|
|
120
|
+
let stdout = '';
|
|
121
|
+
let stderr = '';
|
|
122
|
+
child.stdout.on('data', (data) => {
|
|
123
|
+
stdout += data.toString();
|
|
124
|
+
});
|
|
125
|
+
child.stderr.on('data', (data) => {
|
|
126
|
+
stderr += data.toString();
|
|
127
|
+
});
|
|
128
|
+
const waitFor = (pattern, timeoutMs = 15_000) => new Promise((resolve, reject) => {
|
|
129
|
+
const timer = setTimeout(() => {
|
|
130
|
+
clearInterval(interval);
|
|
131
|
+
reject(new Error(`Timed out waiting for "${pattern}". Stdout so far:\n${stdout}\nStderr so far:\n${stderr}`));
|
|
132
|
+
}, timeoutMs);
|
|
133
|
+
const interval = setInterval(() => {
|
|
134
|
+
if (stdout.includes(pattern)) {
|
|
135
|
+
clearInterval(interval);
|
|
136
|
+
clearTimeout(timer);
|
|
137
|
+
resolve();
|
|
138
|
+
}
|
|
139
|
+
}, 50);
|
|
140
|
+
});
|
|
141
|
+
try {
|
|
142
|
+
await waitFor('Server address and port');
|
|
143
|
+
child.stdin.write(`http://localhost:${authPort}\r`);
|
|
144
|
+
await waitFor('Select login type');
|
|
145
|
+
// Move the selection down from the default "root" choice onto the
|
|
146
|
+
// mock server's "guest" login type, then confirm it.
|
|
147
|
+
child.stdin.write('\u001B[B');
|
|
148
|
+
await new Promise((resolve) => setTimeout(resolve, 500));
|
|
149
|
+
child.stdin.write('\r');
|
|
150
|
+
const exitCode = await new Promise((resolve) => {
|
|
151
|
+
child.on('exit', resolve);
|
|
152
|
+
});
|
|
153
|
+
assert.strictEqual(exitCode, 0, `Expected "apollo config" to exit cleanly. Stdout:\n${stdout}\nStderr:\n${stderr}`);
|
|
154
|
+
assert.ok(!stdout.includes('[object Object]'), `Select choices rendered a raw object instead of its name:\n${stdout}`);
|
|
155
|
+
assert.ok(stdout.includes('guest'));
|
|
156
|
+
}
|
|
157
|
+
finally {
|
|
158
|
+
child.kill();
|
|
159
|
+
authServer.kill();
|
|
160
|
+
fs.unlinkSync(serverScript);
|
|
161
|
+
}
|
|
162
|
+
const p = new Shell(`${apollo} config ${P} accessType`);
|
|
163
|
+
assert.strictEqual(p.stdout.trim(), 'guest');
|
|
164
|
+
});
|
|
88
165
|
void globalThis.itName('Apollo status', () => {
|
|
89
166
|
let p = new Shell(`${apollo} status ${P}`);
|
|
90
167
|
assert.strictEqual(p.stdout.trim(), 'testAdmin: Logged in');
|
|
@@ -319,7 +396,7 @@ void describe('Test CLI', () => {
|
|
|
319
396
|
p = new Shell(`${apollo} assembly get ${P} -a vv1`);
|
|
320
397
|
assert.ok(p.stdout.includes('vv1'));
|
|
321
398
|
p = new Shell(`${apollo} assembly sequence ${P} -a vv1 -r ctgA -s 1 -e 10`);
|
|
322
|
-
const seq = p.stdout.
|
|
399
|
+
const seq = p.stdout.split(' ');
|
|
323
400
|
assert.strictEqual(seq[1], 'cattgttgcg');
|
|
324
401
|
p = new Shell(`${apollo} assembly add-from-fasta ${P} -a vv1 -f https://x.fa.gz --fai https://x.fa.gz.fai --gzi https://x.fa.gz.gzi`, false);
|
|
325
402
|
assert.ok(p.returncode != 0);
|
|
@@ -327,7 +404,7 @@ void describe('Test CLI', () => {
|
|
|
327
404
|
void globalThis.itName('Detect missing external index', () => {
|
|
328
405
|
const p = new Shell(`${apollo} assembly add-from-fasta ${P} -a vv1 -f http://localhost:3131/tiny.fasta`, false);
|
|
329
406
|
assert.ok(p.returncode != 0);
|
|
330
|
-
assert.ok(p.stderr.includes('Index file
|
|
407
|
+
assert.ok(p.stderr.includes('Index file does not exist'));
|
|
331
408
|
});
|
|
332
409
|
void globalThis.itName('Editable sequence not allowed with external source', () => {
|
|
333
410
|
const cmd = `${apollo} assembly add-from-fasta ${P} -a vv1 -f http://localhost:3131/tiny.fasta.gz`;
|
|
@@ -811,9 +888,9 @@ EOF`);
|
|
|
811
888
|
assert.ok(p.stderr.includes('returned 0 assemblies'));
|
|
812
889
|
p = new Shell(`${apollo} assembly sequence ${P} -a v1 -s 0`, false);
|
|
813
890
|
assert.ok(p.returncode != 0);
|
|
814
|
-
assert.
|
|
891
|
+
assert.match(p.stderr, /must be greater than 0/);
|
|
815
892
|
p = new Shell(`${apollo} assembly sequence ${P} -a v1`);
|
|
816
|
-
let seq = p.stdout.
|
|
893
|
+
let seq = p.stdout.split(' ');
|
|
817
894
|
assert.strictEqual(seq.length, 25);
|
|
818
895
|
assert.deepStrictEqual(seq.at(0), '>ctgA:1..420');
|
|
819
896
|
assert.deepStrictEqual(seq.at(1), 'cattgttgcggagttgaacaACGGCATTAGGAACACTTCCGTCTCtcacttttatacgattatgattggttctttagcct');
|
|
@@ -821,11 +898,11 @@ EOF`);
|
|
|
821
898
|
assert.deepStrictEqual(seq.at(7), '>ctgB:1..800');
|
|
822
899
|
assert.deepStrictEqual(seq.at(-1), 'ttggtcgctccgttgtaccc');
|
|
823
900
|
p = new Shell(`${apollo} assembly sequence ${P} -a v1 -r ctgB -s 1 -e 1`);
|
|
824
|
-
seq = p.stdout.split('
|
|
901
|
+
seq = p.stdout.split(' ');
|
|
825
902
|
assert.deepStrictEqual(seq.at(0), '>ctgB:1..1');
|
|
826
903
|
assert.deepStrictEqual(seq.at(1), 'A');
|
|
827
904
|
p = new Shell(`${apollo} assembly sequence ${P} -a v1 -r ctgB -s 2 -e 4`);
|
|
828
|
-
seq = p.stdout.split('
|
|
905
|
+
seq = p.stdout.split(' ');
|
|
829
906
|
assert.deepStrictEqual(seq.at(0), '>ctgB:2..4');
|
|
830
907
|
assert.deepStrictEqual(seq.at(1), 'CAT');
|
|
831
908
|
p = new Shell(`${apollo} assembly sequence ${P} -r ctgB`, false);
|
|
@@ -1165,15 +1242,15 @@ EOF`);
|
|
|
1165
1242
|
new Shell(`${apollo} feature import ${P} test_data/tiny.fasta.gff3 -a vv1`);
|
|
1166
1243
|
let p = new Shell(`${apollo} export gff3 ${P} vv1 --include-fasta`);
|
|
1167
1244
|
let gff = p.stdout;
|
|
1168
|
-
assert.
|
|
1169
|
-
assert.
|
|
1170
|
-
assert.
|
|
1171
|
-
assert.
|
|
1245
|
+
assert.match(gff, /^##gff-version 3/);
|
|
1246
|
+
assert.match(gff, /multivalue=val1,val2,val3/);
|
|
1247
|
+
assert.match(gff, /##FASTA/);
|
|
1248
|
+
assert.match(gff, /taccc$/);
|
|
1172
1249
|
p = new Shell(`${apollo} export gff3 ${P} vv1`);
|
|
1173
1250
|
gff = p.stdout;
|
|
1174
|
-
assert.
|
|
1175
|
-
assert.
|
|
1176
|
-
assert.
|
|
1251
|
+
assert.match(gff, /^##gff-version 3/);
|
|
1252
|
+
assert.match(gff, /multivalue=val1,val2,val3/);
|
|
1253
|
+
assert.doesNotMatch(gff, /##FASTA/);
|
|
1177
1254
|
// Invalid assembly
|
|
1178
1255
|
p = new Shell(`${apollo} export gff3 ${P} foobar`, false);
|
|
1179
1256
|
assert.ok(p.returncode != 0);
|
|
@@ -1184,32 +1261,30 @@ EOF`);
|
|
|
1184
1261
|
new Shell(`${apollo} feature import ${P} test_data/tiny.fasta.gff3 -a vv1`);
|
|
1185
1262
|
let p = new Shell(`${apollo} export gff3 ${P} vv1 --include-fasta`);
|
|
1186
1263
|
let gff = p.stdout;
|
|
1187
|
-
assert.
|
|
1188
|
-
assert.
|
|
1189
|
-
assert.
|
|
1190
|
-
|
|
1191
|
-
assert.deepStrictEqual(gff.slice(-7), 'taccc\n\n');
|
|
1264
|
+
assert.match(gff, /^##gff-version 3/);
|
|
1265
|
+
assert.match(gff, /multivalue=val1,val2,val3/);
|
|
1266
|
+
assert.match(gff, /##FASTA/);
|
|
1267
|
+
assert.match(gff, /taccc$/);
|
|
1192
1268
|
p = new Shell(`${apollo} export gff3 ${P} vv1`);
|
|
1193
1269
|
gff = p.stdout;
|
|
1194
|
-
assert.
|
|
1195
|
-
assert.
|
|
1196
|
-
assert.
|
|
1270
|
+
assert.match(gff, /^##gff-version 3/);
|
|
1271
|
+
assert.match(gff, /multivalue=val1,val2,val3/);
|
|
1272
|
+
assert.doesNotMatch(gff, /##FASTA/);
|
|
1197
1273
|
});
|
|
1198
1274
|
void globalThis.itName('Export gff3 from external assembly', () => {
|
|
1199
1275
|
new Shell(`${apollo} assembly add-from-fasta ${P} http://localhost:3131/tiny.fasta.gz -a vv1 -f`);
|
|
1200
1276
|
new Shell(`${apollo} feature import ${P} test_data/tiny.fasta.gff3 -a vv1`);
|
|
1201
1277
|
let p = new Shell(`${apollo} export gff3 ${P} vv1 --include-fasta`);
|
|
1202
1278
|
let gff = p.stdout;
|
|
1203
|
-
assert.
|
|
1204
|
-
assert.
|
|
1205
|
-
assert.
|
|
1206
|
-
|
|
1207
|
-
assert.deepStrictEqual(gff.slice(-7), 'taccc\n\n');
|
|
1279
|
+
assert.match(gff, /^##gff-version 3/);
|
|
1280
|
+
assert.match(gff, /multivalue=val1,val2,val3/);
|
|
1281
|
+
assert.match(gff, /##FASTA/);
|
|
1282
|
+
assert.match(gff, /taccc$/);
|
|
1208
1283
|
p = new Shell(`${apollo} export gff3 ${P} vv1`);
|
|
1209
1284
|
gff = p.stdout;
|
|
1210
|
-
assert.
|
|
1211
|
-
assert.
|
|
1212
|
-
assert.
|
|
1285
|
+
assert.match(gff, /^##gff-version 3/);
|
|
1286
|
+
assert.match(gff, /multivalue=val1,val2,val3/);
|
|
1287
|
+
assert.doesNotMatch(gff, /##FASTA/);
|
|
1213
1288
|
});
|
|
1214
1289
|
void globalThis.itName('Position of internal stop codon warning in forward', () => {
|
|
1215
1290
|
new Shell(`${apollo} assembly add-from-gff ${P} test_data/warningPositionForward.gff -a vv1 -f`);
|
|
@@ -1341,5 +1416,54 @@ EOF`);
|
|
|
1341
1416
|
chk = out.filter((x) => x.cause === 'NonCanonicalSpliceSiteAtFivePrime' && x.start === 37);
|
|
1342
1417
|
assert.strictEqual(chk.length, 1);
|
|
1343
1418
|
});
|
|
1419
|
+
void globalThis.itName('Timeout option', async () => {
|
|
1420
|
+
// Every CLI request to the real server is preceded by two lightweight
|
|
1421
|
+
// access-token checks (see BaseCommand.getURL/getHeaders), so only the
|
|
1422
|
+
// 3rd request is the one actually governed by --timeout. Delay only
|
|
1423
|
+
// that one so the two checks don't slow the test down.
|
|
1424
|
+
const serverScript = 'test_data/tmp_timeout_server.mjs';
|
|
1425
|
+
fs.writeFileSync(serverScript, `
|
|
1426
|
+
import http from 'node:http'
|
|
1427
|
+
let requestCount = 0
|
|
1428
|
+
const server = http.createServer((req, res) => {
|
|
1429
|
+
requestCount++
|
|
1430
|
+
const respond = () => {
|
|
1431
|
+
res.writeHead(200, { 'Content-Type': 'application/json' })
|
|
1432
|
+
res.end('[]')
|
|
1433
|
+
}
|
|
1434
|
+
if (requestCount % 3 === 0) {
|
|
1435
|
+
setTimeout(respond, 3000)
|
|
1436
|
+
} else {
|
|
1437
|
+
respond()
|
|
1438
|
+
}
|
|
1439
|
+
})
|
|
1440
|
+
server.listen(0, () => {
|
|
1441
|
+
console.log(server.address().port)
|
|
1442
|
+
})
|
|
1443
|
+
`);
|
|
1444
|
+
const server = spawnChildProcess('node', [serverScript]);
|
|
1445
|
+
const port = await new Promise((resolve) => {
|
|
1446
|
+
server.stdout.once('data', (data) => {
|
|
1447
|
+
resolve(data.toString().trim());
|
|
1448
|
+
});
|
|
1449
|
+
});
|
|
1450
|
+
new Shell(`${apollo} config --profile fakeTimeout address http://localhost:${port}`);
|
|
1451
|
+
new Shell(`${apollo} config --profile fakeTimeout accessToken dummytoken`);
|
|
1452
|
+
try {
|
|
1453
|
+
// Timeout shorter than the server's response delay: the request
|
|
1454
|
+
// should fail with a headers timeout error.
|
|
1455
|
+
let p = new Shell(`${apollo} assembly get --profile fakeTimeout --timeout 1s`, false);
|
|
1456
|
+
assert.notStrictEqual(p.returncode, 0);
|
|
1457
|
+
assert.ok(p.stderr.includes('UND_ERR_HEADERS_TIMEOUT'));
|
|
1458
|
+
// Timeout longer than the server's response delay: the request
|
|
1459
|
+
// should succeed.
|
|
1460
|
+
p = new Shell(`${apollo} assembly get --profile fakeTimeout --timeout 10s`);
|
|
1461
|
+
assert.strictEqual(p.stdout.trim(), '[]');
|
|
1462
|
+
}
|
|
1463
|
+
finally {
|
|
1464
|
+
server.kill();
|
|
1465
|
+
fs.unlinkSync(serverScript);
|
|
1466
|
+
}
|
|
1467
|
+
});
|
|
1344
1468
|
});
|
|
1345
1469
|
//# sourceMappingURL=test.js.map
|