Skip to content

Commit 51589e9

Browse files
Move test fixtures earlier in file
1 parent c4b1134 commit 51589e9

1 file changed

Lines changed: 12 additions & 14 deletions

File tree

extensions/ql-vscode/src/vscode-tests/cli-integration/remote-queries/variant-analysis-results-manager.test.ts

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import { CodeQLCliServer } from '../../../cli';
1313
import { storagePath } from '../global.helper';
1414
import { faker } from '@faker-js/faker';
1515
import * as ghApiClient from '../../../remote-queries/gh-api/gh-api-client';
16-
import { VariantAnalysisRepoTask } from '../../../remote-queries/gh-api/variant-analysis';
1716

1817
describe(VariantAnalysisResultsManager.name, function() {
1918
this.timeout(10000);
@@ -47,15 +46,24 @@ describe(VariantAnalysisResultsManager.name, function() {
4746

4847
describe('download', () => {
4948
let getOctokitStub: sinon.SinonStub;
50-
let variantAnalysisStoragePath: string;
5149
const mockCredentials = {
5250
getOctokit: () => Promise.resolve({
5351
request: getOctokitStub
5452
})
5553
} as unknown as Credentials;
54+
let dummyRepoTask = createMockVariantAnalysisRepoTask();
55+
let variantAnalysisStoragePath: string;
56+
let repoTaskStorageDirectory: string;
5657

5758
beforeEach(async () => {
59+
dummyRepoTask = createMockVariantAnalysisRepoTask();
60+
5861
variantAnalysisStoragePath = path.join(storagePath, variantAnalysisId.toString());
62+
repoTaskStorageDirectory = variantAnalysisResultsManager.getRepoStorageDirectory(variantAnalysisStoragePath, dummyRepoTask.repository.full_name);
63+
});
64+
65+
afterEach(async () => {
66+
fs.rmSync(variantAnalysisStoragePath, { recursive: true });
5967
});
6068

6169
describe('when the artifact_url is missing', async () => {
@@ -79,14 +87,9 @@ describe(VariantAnalysisResultsManager.name, function() {
7987
});
8088

8189
describe('when the artifact_url is present', async () => {
82-
let dummyRepoTask: VariantAnalysisRepoTask;
83-
let storageDirectory: string;
8490
let arrayBuffer: ArrayBuffer;
8591

8692
beforeEach(async () => {
87-
dummyRepoTask = createMockVariantAnalysisRepoTask();
88-
89-
storageDirectory = variantAnalysisResultsManager.getRepoStorageDirectory(variantAnalysisStoragePath, dummyRepoTask.repository.full_name);
9093
const sourceFilePath = path.join(__dirname, '../../../../src/vscode-tests/cli-integration/data/variant-analysis-results.zip');
9194
arrayBuffer = fs.readFileSync(sourceFilePath).buffer;
9295

@@ -96,11 +99,6 @@ describe(VariantAnalysisResultsManager.name, function() {
9699
.resolves(arrayBuffer);
97100
});
98101

99-
afterEach(async () => {
100-
fs.removeSync(`${storageDirectory}/results.zip`);
101-
fs.removeSync(`${storageDirectory}/results`);
102-
});
103-
104102
it('should call the API to download the results', async () => {
105103
await variantAnalysisResultsManager.download(
106104
mockCredentials,
@@ -120,7 +118,7 @@ describe(VariantAnalysisResultsManager.name, function() {
120118
variantAnalysisStoragePath
121119
);
122120

123-
expect(fs.existsSync(`${storageDirectory}/results.zip`)).to.be.true;
121+
expect(fs.existsSync(`${repoTaskStorageDirectory}/results.zip`)).to.be.true;
124122
});
125123

126124
it('should unzip the results in a `results/` folder', async () => {
@@ -131,7 +129,7 @@ describe(VariantAnalysisResultsManager.name, function() {
131129
variantAnalysisStoragePath
132130
);
133131

134-
expect(fs.existsSync(`${storageDirectory}/results/results.sarif`)).to.be.true;
132+
expect(fs.existsSync(`${repoTaskStorageDirectory}/results/results.sarif`)).to.be.true;
135133
});
136134
});
137135
});

0 commit comments

Comments
 (0)