Skip to content

Commit 699b8cc

Browse files
authored
Fix scheduled CLI output test by moving TEMP_DIR outside of Git repository (#2697)
1 parent f16c3a6 commit 699b8cc

File tree

5 files changed

+19
-46
lines changed

5 files changed

+19
-46
lines changed

extension/src/cli/git/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export enum Command {
1414
CLEAN = 'clean',
1515
COMMIT = 'commit',
1616
DIFF = 'diff',
17+
INITIALIZE = 'init',
1718
LS_FILES = 'ls-files',
1819
PUSH = 'push',
1920
RESET = 'reset',

extension/src/cli/git/executor.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@ export class GitExecutor extends GitCli {
1717
this
1818
)
1919

20+
public init(cwd: string) {
21+
const options = getOptions(cwd, Command.INITIALIZE)
22+
23+
return this.executeProcess(options)
24+
}
25+
2026
public pushBranch(cwd: string, branchName?: string) {
2127
const args: Args = [Command.PUSH, Flag.SET_UPSTREAM, DEFAULT_REMOTE]
2228

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { join } from 'path'
1+
import { resolve } from 'path'
22

33
export const ENV_DIR = '.env'
4-
export const TEMP_DIR = join(__dirname, 'temp')
4+
export const TEMP_DIR = resolve(__dirname, '..', '..', '..', '..', '..', 'temp')

extension/src/test/cli/expShow.test.ts

Lines changed: 4 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { describe, it, suite } from 'mocha'
22
import isEmpty from 'lodash.isempty'
3-
import omit from 'lodash.omit'
43
import { expect } from 'chai'
54
import { TEMP_DIR } from './constants'
65
import { dvcReader, initializeDemoRepo, initializeEmptyRepo } from './util'
@@ -77,50 +76,13 @@ suite('exp show --show-json', () => {
7776
})
7877

7978
describe('Empty Repository', () => {
80-
it('should return the expected output', async () => {
79+
it('should return the default output', async () => {
8180
await initializeEmptyRepo()
8281
const output = await dvcReader.expShow(TEMP_DIR)
8382

84-
expect(
85-
Object.keys(output),
86-
'should have at least two entries'
87-
).to.have.lengthOf.greaterThanOrEqual(2)
88-
89-
const { workspace } = output
90-
91-
expect(workspace, 'should have a workspace key').not.to.be.undefined
92-
93-
const data = workspace.baseline.data
94-
95-
expect(
96-
data,
97-
'should have data inside of the workspace baseline'
98-
).to.be.an('object')
99-
100-
expect(data?.timestamp, 'should have a timestamp').to.be.a('null')
101-
102-
expect(data?.deps, 'should have deps inside of the workspace').to.be.an(
103-
'object'
104-
)
105-
106-
expect(data?.outs, 'should have outs inside of the workspace').to.be.an(
107-
'object'
108-
)
109-
110-
expect(
111-
data?.metrics,
112-
'should have metrics inside of the workspace'
113-
).to.be.an('object')
114-
115-
expect(
116-
data?.params,
117-
'should not have params inside of the workspace'
118-
).to.be.a('undefined')
119-
120-
for (const obj of Object.values(omit(output, 'workspace'))) {
121-
expect(obj, 'should have a child object').to.be.an('object')
122-
expect(obj.baseline, 'should have a baseline entry').to.be.an('object')
123-
}
83+
expect(output).to.deep.equal({
84+
workspace: { baseline: {} }
85+
})
12486
})
12587
})
12688
})

extension/src/test/cli/util.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { Config } from '../../config'
66
import { exists } from '../../fileSystem'
77
import { getVenvBinPath } from '../../python/path'
88
import { dvcDemoPath } from '../util'
9+
import { GitExecutor } from '../../cli/git/executor'
910

1011
const config = {
1112
getCliPath: () => '',
@@ -14,6 +15,7 @@ const config = {
1415

1516
export const dvcReader = new DvcReader(config)
1617
export const dvcExecutor = new DvcExecutor(config)
18+
const gitExecutor = new GitExecutor()
1719

1820
let demoInitialized: Promise<string>
1921
export const initializeDemoRepo = (): Promise<string> => {
@@ -23,10 +25,12 @@ export const initializeDemoRepo = (): Promise<string> => {
2325
return demoInitialized
2426
}
2527

26-
export const initializeEmptyRepo = (): Promise<string> => {
28+
export const initializeEmptyRepo = async (): Promise<string> => {
2729
if (exists(join(TEMP_DIR, '.dvc'))) {
28-
return Promise.resolve('')
30+
return ''
2931
}
3032

33+
await gitExecutor.init(TEMP_DIR)
34+
3135
return dvcExecutor.init(TEMP_DIR)
3236
}

0 commit comments

Comments
 (0)