Repository navigation
Expand file tree
/
Copy pathcontext.test.ts
More file actions
47 lines (39 loc) · 1.57 KB
/
Copy pathcontext.test.ts
File metadata and controls
47 lines (39 loc) · 1.57 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
import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs'
import { tmpdir } from 'node:os'
import path from 'node:path'
import { afterEach, describe, expect, it } from 'vitest'
import { resolveSetupContext } from './context'
const roots: string[] = []
function tempRoot(): string {
const root = mkdtempSync(path.join(tmpdir(), 'sim-setup-context-'))
roots.push(root)
return root
}
function writePackage(root: string, relativePath: string, name: string): void {
const file = path.join(root, relativePath)
mkdirSync(path.dirname(file), { recursive: true })
writeFileSync(file, JSON.stringify({ name }))
}
afterEach(() => {
for (const root of roots.splice(0)) rmSync(root, { recursive: true, force: true })
})
describe('resolveSetupContext', () => {
it('fails on a partial Sim checkout', () => {
const root = tempRoot()
writePackage(root, 'package.json', 'simstudio')
writePackage(root, 'apps/sim/package.json', '@sim/app')
expect(() => resolveSetupContext(root, [])).toThrow('Incomplete Sim source checkout')
})
it('does not replace an explicit standalone directory with an ancestor checkout', () => {
const root = tempRoot()
writePackage(root, 'package.json', 'simstudio')
writePackage(root, 'apps/sim/package.json', '@sim/app')
writePackage(root, 'apps/realtime/package.json', '@sim/realtime')
writePackage(root, 'packages/db/package.json', '@sim/db')
expect(resolveSetupContext(root, ['--dir', 'deployment'])).toEqual({
kind: 'standalone',
root: path.join(root, 'deployment'),
existing: false,
})
})
})