Use real CancellationTokenSource in tests

This will change tests that are using a mocked `CancellationTokenSource`
to use a real `CancellationTokenSource` instead. Tests are run inside
VSCode, so we can use these without mocking.
This commit is contained in:
Koen Vlaswinkel
2022-10-07 14:30:44 +02:00
parent b4fbfb6d2b
commit f0d71ba356
3 changed files with 7 additions and 28 deletions

View File

@@ -56,14 +56,7 @@ describe('Remote queries', function() {
} }
credentials = {} as unknown as Credentials; credentials = {} as unknown as Credentials;
cancellationTokenSource = { cancellationTokenSource = new CancellationTokenSource();
token: {
isCancellationRequested: false,
onCancellationRequested: sandbox.stub()
},
cancel: sandbox.stub(),
dispose: sandbox.stub()
};
progress = sandbox.spy(); progress = sandbox.spy();
// Should not have asked for a language // Should not have asked for a language
@@ -282,7 +275,7 @@ describe('Remote queries', function() {
const promise = runRemoteQuery(cli, credentials, fileUri, true, progress, cancellationTokenSource.token); const promise = runRemoteQuery(cli, credentials, fileUri, true, progress, cancellationTokenSource.token);
cancellationTokenSource.token.isCancellationRequested = true; cancellationTokenSource.cancel();
try { try {
await promise; await promise;
@@ -347,7 +340,7 @@ describe('Remote queries', function() {
const promise = runRemoteQuery(cli, credentials, fileUri, true, progress, cancellationTokenSource.token); const promise = runRemoteQuery(cli, credentials, fileUri, true, progress, cancellationTokenSource.token);
cancellationTokenSource.token.isCancellationRequested = true; cancellationTokenSource.cancel();
try { try {
await promise; await promise;

View File

@@ -36,14 +36,7 @@ describe('Variant Analysis Manager', async function() {
sandbox.stub(fs, 'mkdirSync'); sandbox.stub(fs, 'mkdirSync');
sandbox.stub(fs, 'writeFile'); sandbox.stub(fs, 'writeFile');
cancellationTokenSource = { cancellationTokenSource = new CancellationTokenSource();
token: {
isCancellationRequested: false,
onCancellationRequested: sandbox.stub()
},
cancel: sandbox.stub(),
dispose: sandbox.stub()
};
scannedRepos = createMockScannedRepos(); scannedRepos = createMockScannedRepos();
variantAnalysis = createMockApiResponse('in_progress', scannedRepos); variantAnalysis = createMockApiResponse('in_progress', scannedRepos);
@@ -120,7 +113,7 @@ describe('Variant Analysis Manager', async function() {
}); });
it('should return early if variant analysis is cancelled', async () => { it('should return early if variant analysis is cancelled', async () => {
cancellationTokenSource.token.isCancellationRequested = true; cancellationTokenSource.cancel();
await variantAnalysisManager.autoDownloadVariantAnalysisResult( await variantAnalysisManager.autoDownloadVariantAnalysisResult(
scannedRepos[0], scannedRepos[0],

View File

@@ -31,14 +31,7 @@ describe('Variant Analysis Monitor', async function() {
sandbox.stub(logger, 'log'); sandbox.stub(logger, 'log');
sandbox.stub(config, 'isVariantAnalysisLiveResultsEnabled').returns(false); sandbox.stub(config, 'isVariantAnalysisLiveResultsEnabled').returns(false);
cancellationTokenSource = { cancellationTokenSource = new CancellationTokenSource();
token: {
isCancellationRequested: false,
onCancellationRequested: sandbox.stub()
},
cancel: sandbox.stub(),
dispose: sandbox.stub()
};
variantAnalysis = createMockVariantAnalysis(); variantAnalysis = createMockVariantAnalysis();
@@ -79,7 +72,7 @@ describe('Variant Analysis Monitor', async function() {
}); });
it('should return early if variant analysis is cancelled', async () => { it('should return early if variant analysis is cancelled', async () => {
cancellationTokenSource.token.isCancellationRequested = true; cancellationTokenSource.cancel();
const result = await variantAnalysisMonitor.monitorVariantAnalysis(variantAnalysis, cancellationTokenSource.token); const result = await variantAnalysisMonitor.monitorVariantAnalysis(variantAnalysis, cancellationTokenSource.token);