-
Notifications
You must be signed in to change notification settings - Fork 70
/
Copy pathe2e-snippet.spec.ts
124 lines (110 loc) · 3.77 KB
/
e2e-snippet.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
import { promises as fs } from 'fs';
import path from 'path';
import { expect } from 'chai';
import type { TestShell } from './test-shell';
import { useTmpdir } from './repl-helpers';
import { eventually } from '../../../testing/eventually';
describe('snippet integration tests', function () {
this.timeout(120_000);
const tmpdir = useTmpdir();
let shell: TestShell;
let makeTestShell: () => TestShell;
beforeEach(async function () {
if (process.env.DISTRO_ID === 'rhel93-fips') {
// TODO: The HTTPS requests we are making for snippet support do not work
// with the FIPS configuration on the RHEL 9.3 FIPS-enabled machines.
return this.skip();
}
makeTestShell = () =>
this.startTestShell({
args: ['--nodb'],
cwd: tmpdir.path,
env: {
...process.env,
HOME: tmpdir.path,
APPDATA: tmpdir.path,
LOCALAPPDATA: tmpdir.path,
MONGOSH_FORCE_TERMINAL: '1',
},
});
shell = makeTestShell();
await shell.waitForPrompt();
shell.assertNoErrors();
// make nyc happy when spawning npm below
await fs.mkdir(
path.join(tmpdir.path, '.mongodb', '.nyc_output', 'processinfo'),
{ recursive: true }
);
await fs.mkdir(
path.join(tmpdir.path, 'mongodb', '.nyc_output', 'processinfo'),
{ recursive: true }
);
});
it('allows managing snippets', async function () {
shell.writeInputLine('snippet install analyze-schema');
await shell.eventually(
() => {
shell.assertContainsOutput(
'Installed new snippets analyze-schema. Do you want to load them now?'
);
},
{ timeout: 90_000 }
);
shell.writeInput('Y');
await shell.waitForPrompt(shell.output.length);
const installed = await shell.executeLine('snippet ls');
expect(installed).to.include(tmpdir.path);
expect(installed).to.match(/mongosh:analyze-schema@/);
const analyzedSchema = await shell.executeLine(`\
schema({
tryNext() {
return (this.i = (this.i + 1) || 0) < 10 ? { prop: "value" } : null;
}
})`);
expect(analyzedSchema).to.match(/\bprop\b.+100.0 %.+\bString\b/);
shell.assertNoErrors();
});
it('autocompletes snippet commands', async function () {
if (process.arch === 's390x') {
return this.skip(); // https://jira.mongodb.org/browse/MONGOSH-746
}
shell.writeInput('snippet insta\t');
await shell.eventually(() => {
shell.assertContainsOutput('snippet install');
});
});
it('works when an index file is inaccessible', async function () {
await shell.executeLine(
'config.set("snippetIndexSourceURLs", "http://localhost:1/")'
);
shell.writeInputLine('exit');
await shell.waitForExit();
shell = makeTestShell();
await shell.waitForPrompt();
shell.assertNoErrors(); // This is the important assertion here
const consistencyCheck = await shell.executeLine(
'config.get("snippetIndexSourceURLs")'
);
expect(consistencyCheck).to.include('http://localhost:1/');
const commandResult = await shell.executeLine('snippet search');
expect(commandResult).to.include(
'FetchError: request to http://localhost:1/ failed'
);
});
it('has proper async rewriting support', async function () {
const commandResult = await shell.executeLine(
'({ works: snippet("ls").includes("snippets") })'
);
expect(commandResult).to.include('{ works: true }');
});
it('informs about the mongocompat snippet', async function () {
await eventually(
async () => {
expect(await shell.executeLine('Date.timeFunc()')).to.match(
/Date.timeFunc is not a function.+Try running `snippet install mongocompat`/
);
},
{ timeout: 30_000 }
);
});
});