search-module.ts
1.41 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
import { expect } from 'chai';
import * as fs from 'fs-extra';
import * as os from 'os';
import * as path from 'path';
import { getProjectRootPath } from '../src/search-module';
let baseDir: string;
async function createTempDir(): Promise<void> {
baseDir = await fs.mkdtemp(path.join(os.tmpdir(), 'electron-rebuild-test-'));
}
async function removeTempDir(): Promise<void> {
await fs.remove(baseDir);
}
describe('search-module', () => {
describe('getProjectRootPath', () => {
describe('multi-level workspace', () => {
for (const lockFile of ['yarn.lock', 'package-lock.json']) {
describe(lockFile, () => {
before(async () => {
await createTempDir();
await fs.copy(path.resolve(__dirname, 'fixture', 'multi-level-workspace'), baseDir);
await fs.ensureFile(path.join(baseDir, lockFile));
});
it('finds the folder with the lockfile', async () => {
const packageDir = path.join(baseDir, 'packages', 'bar');
expect(await getProjectRootPath(packageDir)).to.equal(baseDir);
});
after(removeTempDir);
});
}
});
describe('no workspace', () => {
before(createTempDir);
it('returns the input directory if a lockfile cannot be found', async () => {
expect(await getProjectRootPath(baseDir)).to.equal(baseDir);
});
after(removeTempDir);
});
});
});