Skip to content

Commit 81e6725

Browse files
committed
update tests
1 parent be12c96 commit 81e6725

File tree

2 files changed

+184
-0
lines changed

2 files changed

+184
-0
lines changed
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// Licensed under the MIT License.
3+
4+
import { assert } from 'chai';
5+
import * as fs from 'fs-extra';
6+
import * as path from '../../../platform/vscode-path/path';
7+
import * as os from 'os';
8+
import { FileSystem } from './fileSystem.node';
9+
10+
suite('FileSystem - glob functionality', () => {
11+
let fileSystem: FileSystem;
12+
let tempDir: string;
13+
14+
setup(async () => {
15+
fileSystem = new FileSystem();
16+
tempDir = await fs.mkdtemp(path.join(os.tmpdir(), 'vscode-deepnote-test-'));
17+
});
18+
19+
teardown(async () => {
20+
await fs.remove(tempDir);
21+
});
22+
23+
test('searchLocal should find files matching pattern', async () => {
24+
// Create test files
25+
await fs.writeFile(path.join(tempDir, 'test1.ts'), 'content');
26+
await fs.writeFile(path.join(tempDir, 'test2.ts'), 'content');
27+
await fs.writeFile(path.join(tempDir, 'test.js'), 'content');
28+
29+
const results = await fileSystem.searchLocal('*.ts', tempDir);
30+
31+
assert.strictEqual(results.length, 2);
32+
assert.ok(results.some((f) => f.endsWith('test1.ts')));
33+
assert.ok(results.some((f) => f.endsWith('test2.ts')));
34+
});
35+
36+
test('searchLocal should find files in subdirectories with ** pattern', async () => {
37+
// Create test files in subdirectories
38+
await fs.ensureDir(path.join(tempDir, 'sub1'));
39+
await fs.ensureDir(path.join(tempDir, 'sub2'));
40+
await fs.writeFile(path.join(tempDir, 'sub1', 'test1.ts'), 'content');
41+
await fs.writeFile(path.join(tempDir, 'sub2', 'test2.ts'), 'content');
42+
43+
const results = await fileSystem.searchLocal('**/*.ts', tempDir);
44+
45+
assert.strictEqual(results.length, 2);
46+
assert.ok(results.some((f) => f.includes('sub1') && f.endsWith('test1.ts')));
47+
assert.ok(results.some((f) => f.includes('sub2') && f.endsWith('test2.ts')));
48+
});
49+
50+
test('searchLocal should find hidden files when dot option is true', async () => {
51+
// Create hidden file
52+
await fs.writeFile(path.join(tempDir, '.hidden.ts'), 'content');
53+
await fs.writeFile(path.join(tempDir, 'visible.ts'), 'content');
54+
55+
const results = await fileSystem.searchLocal('*.ts', tempDir, true);
56+
57+
assert.ok(results.length >= 2);
58+
assert.ok(results.some((f) => f.endsWith('.hidden.ts')));
59+
assert.ok(results.some((f) => f.endsWith('visible.ts')));
60+
});
61+
62+
test('searchLocal should not find hidden files when dot option is false', async () => {
63+
// Create hidden file
64+
await fs.writeFile(path.join(tempDir, '.hidden.ts'), 'content');
65+
await fs.writeFile(path.join(tempDir, 'visible.ts'), 'content');
66+
67+
const results = await fileSystem.searchLocal('*.ts', tempDir, false);
68+
69+
assert.strictEqual(results.length, 1);
70+
assert.ok(results.some((f) => f.endsWith('visible.ts')));
71+
assert.ok(!results.some((f) => f.endsWith('.hidden.ts')));
72+
});
73+
74+
test('searchLocal should return empty array when no files match', async () => {
75+
const results = await fileSystem.searchLocal('*.nonexistent', tempDir);
76+
77+
assert.strictEqual(results.length, 0);
78+
});
79+
80+
test('searchLocal should handle patterns with multiple extensions', async () => {
81+
await fs.writeFile(path.join(tempDir, 'test.ts'), 'content');
82+
await fs.writeFile(path.join(tempDir, 'test.js'), 'content');
83+
await fs.writeFile(path.join(tempDir, 'test.py'), 'content');
84+
85+
const results = await fileSystem.searchLocal('*.{ts,js}', tempDir);
86+
87+
assert.strictEqual(results.length, 2);
88+
assert.ok(results.some((f) => f.endsWith('.ts')));
89+
assert.ok(results.some((f) => f.endsWith('.js')));
90+
assert.ok(!results.some((f) => f.endsWith('.py')));
91+
});
92+
});
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// Licensed under the MIT License.
3+
4+
/* eslint-disable local-rules/dont-use-process */
5+
6+
import { assert } from 'chai';
7+
import * as path from '../../platform/vscode-path/path';
8+
import * as fs from 'fs-extra';
9+
import * as os from 'os';
10+
import { getCondaFile } from './condaService.node';
11+
import { glob } from 'glob';
12+
13+
suite('condaService - glob functionality', () => {
14+
let originalEnv: string | undefined;
15+
let tempDir: string;
16+
17+
setup(async () => {
18+
// Save original environment variable
19+
originalEnv = process.env.CI_PYTHON_CONDA_PATH;
20+
delete process.env.CI_PYTHON_CONDA_PATH;
21+
22+
// Create a temporary directory for testing
23+
tempDir = await fs.mkdtemp(path.join(os.tmpdir(), 'conda-test-'));
24+
});
25+
26+
teardown(async () => {
27+
// Restore environment variable
28+
if (originalEnv !== undefined) {
29+
process.env.CI_PYTHON_CONDA_PATH = originalEnv;
30+
} else {
31+
delete process.env.CI_PYTHON_CONDA_PATH;
32+
}
33+
34+
// Clean up temp directory
35+
await fs.remove(tempDir);
36+
});
37+
38+
test('getCondaFile should use CI_PYTHON_CONDA_PATH when set', async () => {
39+
process.env.CI_PYTHON_CONDA_PATH = '/custom/conda/path';
40+
41+
const result = await getCondaFile();
42+
43+
assert.strictEqual(result, '/custom/conda/path');
44+
});
45+
46+
test('glob should work with basic patterns', async () => {
47+
// Create test files
48+
await fs.writeFile(path.join(tempDir, 'conda'), 'test');
49+
await fs.writeFile(path.join(tempDir, 'python'), 'test');
50+
51+
const results = await glob('conda', { cwd: tempDir });
52+
53+
assert.strictEqual(results.length, 1);
54+
assert.ok(results[0].includes('conda'));
55+
});
56+
57+
test('glob should work with wildcard patterns', async () => {
58+
// Create test files
59+
await fs.writeFile(path.join(tempDir, 'conda1'), 'test');
60+
await fs.writeFile(path.join(tempDir, 'conda2'), 'test');
61+
await fs.writeFile(path.join(tempDir, 'python'), 'test');
62+
63+
const results = await glob('conda*', { cwd: tempDir });
64+
65+
assert.strictEqual(results.length, 2);
66+
});
67+
68+
test('glob should handle brace expansion patterns', async () => {
69+
// Create test files
70+
await fs.writeFile(path.join(tempDir, 'conda'), 'test');
71+
await fs.writeFile(path.join(tempDir, 'miniconda'), 'test');
72+
await fs.writeFile(path.join(tempDir, 'python'), 'test');
73+
74+
const results = await glob('{conda,miniconda}', { cwd: tempDir });
75+
76+
assert.strictEqual(results.length, 2);
77+
assert.ok(results.some((r) => r.includes('conda')));
78+
assert.ok(results.some((r) => r.includes('miniconda')));
79+
});
80+
81+
test('glob should return empty array when no matches found', async () => {
82+
const results = await glob('nonexistent*', { cwd: tempDir });
83+
84+
assert.strictEqual(results.length, 0);
85+
});
86+
87+
test('glob should handle errors gracefully with catch', async () => {
88+
const results = await glob('/nonexistent/path/**/*', {}).catch(() => []);
89+
90+
assert.deepStrictEqual(results, []);
91+
});
92+
});

0 commit comments

Comments
 (0)