forked from microsoft/vscode-python
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathutils.unit.test.ts
More file actions
50 lines (37 loc) · 1.68 KB
/
utils.unit.test.ts
File metadata and controls
50 lines (37 loc) · 1.68 KB
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
import * as assert from 'assert';
import * as sinon from 'sinon';
import * as fs from 'fs';
import * as path from 'path';
import * as os from 'os';
import { writeTestIdsFile } from '../../../client/testing/testController/common/utils';
import { EXTENSION_ROOT_DIR } from '../../../client/constants';
suite('writeTestIdsFile tests', () => {
let sandbox: sinon.SinonSandbox;
setup(() => {
sandbox = sinon.createSandbox();
});
teardown(() => {
sandbox.restore();
});
test('should write test IDs to a temporary file', async () => {
const testIds = ['test1', 'test2', 'test3'];
const writeFileStub = sandbox.stub(fs.promises, 'writeFile').resolves();
const result = await writeTestIdsFile(testIds);
const tmpDir = os.tmpdir();
assert.ok(result.startsWith(tmpDir));
assert.ok(writeFileStub.calledOnceWith(sinon.match.string, testIds.join('\n')));
});
test('should handle error when accessing temp directory', async () => {
const testIds = ['test1', 'test2', 'test3'];
const error = new Error('Access error');
const accessStub = sandbox.stub(fs.promises, 'access').rejects(error);
const writeFileStub = sandbox.stub(fs.promises, 'writeFile').resolves();
const mkdirStub = sandbox.stub(fs.promises, 'mkdir').resolves();
const result = await writeTestIdsFile(testIds);
const tempFileFolder = path.join(EXTENSION_ROOT_DIR, '.temp');
assert.ok(result.startsWith(tempFileFolder));
assert.ok(accessStub.called);
assert.ok(mkdirStub.called);
assert.ok(writeFileStub.calledOnceWith(sinon.match.string, testIds.join('\n')));
});
});