From d94aa6fd34b3ffc362cda927ae696a80c270037b Mon Sep 17 00:00:00 2001 From: Mate Pek Date: Sat, 20 Oct 2018 10:21:12 +0200 Subject: [PATCH] test refactor --- package-lock.json | 2 +- package.json | 2 +- src/test/C2TestAdapter.test.ts | 786 ++++++++++++++++++++++++--------- 3 files changed, 587 insertions(+), 203 deletions(-) diff --git a/package-lock.json b/package-lock.json index ec851d2c..9a2fa10b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "vscode-catch2-test-adapter", - "version": "1.1.1", + "version": "1.1.2", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 5f1f0e91..4d71aaa8 100644 --- a/package.json +++ b/package.json @@ -150,4 +150,4 @@ } } } -} \ No newline at end of file +} diff --git a/src/test/C2TestAdapter.test.ts b/src/test/C2TestAdapter.test.ts index 26b84ee5..d903f0c1 100644 --- a/src/test/C2TestAdapter.test.ts +++ b/src/test/C2TestAdapter.test.ts @@ -8,11 +8,11 @@ import * as fse from 'fs-extra'; import * as assert from 'assert'; import {EventEmitter} from 'events'; import * as vscode from 'vscode'; -import {TestEvent, TestLoadFinishedEvent, TestLoadStartedEvent, TestRunFinishedEvent, TestRunStartedEvent, TestSuiteEvent, TestSuiteInfo} from 'vscode-test-adapter-api'; +import {TestEvent, TestLoadFinishedEvent, TestLoadStartedEvent, TestRunFinishedEvent, TestRunStartedEvent, TestSuiteEvent, TestSuiteInfo, TestInfo, TestAdapter} from 'vscode-test-adapter-api'; import {Log} from 'vscode-test-adapter-util'; import {C2AllTestSuiteInfo} from '../C2AllTestSuiteInfo'; -import * as myExtension from '../C2TestAdapter'; +import {C2TestAdapter} from '../C2TestAdapter'; import {Stream} from 'stream'; import {inspect} from 'util'; @@ -30,25 +30,268 @@ const dotVscodePath = path.join(workspaceFolderUri.path, '.vscode'); const sinonSandbox = sinon.createSandbox(); +const example1 = new class { + readonly suite1 = new class { + readonly execPath = path.join(workspaceFolderUri.path, 'execPath1'); + readonly testList = 'Matching test cases:\n' + + ' s1t1\n' + + ' suite1.cpp:7\n' + + ' tag1\n' + + ' s1t2\n' + + ' suite1.cpp:13\n' + + ' tag1\n' + + '2 matching test cases\n' + + '\n'; + + readonly t1 = new class { + readonly fullTestName = 's1t1'; + assert(test: TestInfo, uniqeIdContainer?: Set) { + assert.equal(test.type, 'test'); + assert.equal(test.label, 's1t1'); + assert.equal( + test.file, path.join(workspaceFolderUri.path, 'suite1.cpp')); + assert.equal(test.line, 7 - 1); + assert.ok(test.skipped == undefined || test.skipped === false); + if (uniqeIdContainer != undefined) { + assert.ok(!uniqeIdContainer.has(test.id)); + uniqeIdContainer.add(test.id); + } + }; + + readonly xml = ` + + + `; + }; + + readonly t2 = new class { + readonly fullTestName = 's1t2'; + assert(test: TestInfo, uniqeIdContainer?: Set) { + assert.equal(test.type, 'test'); + assert.equal(test.label, 's1t2'); + assert.equal( + test.file, path.join(workspaceFolderUri.path, 'suite1.cpp')); + assert.equal(test.line, 13 - 1); + assert.ok(test.skipped == undefined || test.skipped === false); + if (uniqeIdContainer != undefined) { + assert.ok(!uniqeIdContainer.has(test.id)); + uniqeIdContainer.add(test.id); + } + }; + + readonly xml = ` + + + + std::false_type::value + + + false + + + + `; + }; + + assert(suite: TestSuiteInfo, uniqeIdContainer?: Set) { + assert.equal(suite.type, 'suite'); + assert.equal(suite.label, 'execPath1'); + assert.equal( + suite.file, path.join(workspaceFolderUri.path, 'suite1.cpp')); + assert.equal(suite.line, 0); + assert.equal(suite.children.length, 2); + this.t1.assert(suite.children[0], uniqeIdContainer); + this.t2.assert(suite.children[1], uniqeIdContainer); + if (uniqeIdContainer != undefined) { + assert.ok(!uniqeIdContainer.has(suite.id)); + uniqeIdContainer.add(suite.id); + } + } + + readonly xmlHeader = ` + + + `; + + readonly xmlFull = this.xmlHeader + this.t1.xml + this.t2.xml + ` + + + + `; + }; + + readonly suite2 = new class { + readonly execPath = path.join(workspaceFolderUri.path, 'execPath2'); + readonly testList = 'Matching test cases:\n' + + ' s2t1\n' + + ' suite2.cpp:7\n' + + ' tag1\n' + + ' s2t2\n' + + ' suite2.cpp:13\n' + + ' tag1\n' + + ' [.]\n' + + ' s2t3\n' + + ' suite2.cpp:19\n' + + ' tag1\n' + + '3 matching test cases\n' + + '\n'; + + readonly t1 = new class { + readonly fullTestName = 's2t1'; + assert(test: TestInfo, uniqeIdContainer?: Set) { + assert.equal(test.type, 'test'); + assert.equal(test.label, 's2t1'); + assert.equal( + test.file, path.join(workspaceFolderUri.path, 'suite2.cpp')); + assert.equal(test.line, 7 - 1); + assert.ok(test.skipped == undefined || test.skipped === false); + if (uniqeIdContainer != undefined) { + assert.ok(!uniqeIdContainer.has(test.id)); + uniqeIdContainer.add(test.id); + } + }; + + readonly xml = ` + + + `; + }; + + readonly t2 = new class { + readonly fullTestName = 's2t2'; + assert(test: TestInfo, uniqeIdContainer?: Set) { + assert.equal(test.type, 'test'); + assert.equal(test.label, 's2t2 [.]'); + assert.equal( + test.file, path.join(workspaceFolderUri.path, 'suite2.cpp')); + assert.equal(test.line, 13 - 1); + assert.ok(test.skipped === true); + if (uniqeIdContainer != undefined) { + assert.ok(!uniqeIdContainer.has(test.id)); + uniqeIdContainer.add(test.id); + } + }; + + readonly xml = ` + + + `; + }; + + readonly t3 = new class { + readonly fullTestName = 's2t3'; + assert(test: TestInfo, uniqeIdContainer?: Set) { + assert.equal(test.type, 'test'); + assert.equal(test.label, 's2t3'); + assert.equal( + test.file, path.join(workspaceFolderUri.path, 'suite2.cpp')); + assert.equal(test.line, 19 - 1); + assert.ok(test.skipped == undefined || test.skipped === false); + if (uniqeIdContainer != undefined) { + assert.ok(!uniqeIdContainer.has(test.id)); + uniqeIdContainer.add(test.id); + } + }; + + readonly xml = ` + + + + std::false_type::value + + + false + + + + `; + }; + + assert(suite: TestSuiteInfo, uniqeIdContainer?: Set) { + assert.equal(suite.type, 'suite'); + assert.equal(suite.label, 'execPath2'); + assert.equal( + suite.file, path.join(workspaceFolderUri.path, 'suite2.cpp')); + assert.equal(suite.line, 0); + assert.equal(suite.children.length, 3); + this.t1.assert(suite.children[0], uniqeIdContainer); + this.t2.assert(suite.children[1], uniqeIdContainer); + this.t3.assert(suite.children[2], uniqeIdContainer); + if (uniqeIdContainer != undefined) { + assert.ok(!uniqeIdContainer.has(suite.id)); + uniqeIdContainer.add(suite.id); + } + } + + readonly xmlHeader = ` + + + `; + + readonly xmlFull = this.xmlHeader + this.t1.xml + + /* this.t2.xml is skipped */ this.t3.xml + ` + + + + `; + }; + + assertWithoutChildren(root: TestSuiteInfo, uniqeIdContainer?: Set) { + assert.equal(root.type, 'suite'); + assert.equal(root.label, 'AllTests'); + assert.equal(root.file, undefined); + assert.equal(root.line, undefined); + if (uniqeIdContainer != undefined) { + assert.ok(!uniqeIdContainer.has(root.id)); + uniqeIdContainer.add(root.id); + } + }; +}; + +class ChildProcessStub extends EventEmitter { + readonly stdout = new Stream.Readable(); + + constructor(data?: string) { + super(); + this.stdout.on('end', () => { + this.emit('close', 1); + }); + if (data != undefined) this.writeAndClose(data); + } + + writeAndClose(data: string): void { + this.stdout.push(data); + this.stdout.push(null); + } + + writeLineByLineAndClose(data: string): void { + const lines = data.split('\n'); + lines.forEach((l) => { + this.stdout.push(l); + }); + this.stdout.push(null); + } +}; + /// describe('C2TestAdapter', function() { const config = vscode.workspace.getConfiguration( 'catch2TestExplorer', workspaceFolderUri); - const disposable: vscode.Disposable[] = []; - - let adapter: myExtension.C2TestAdapter|undefined; + let adapter: C2TestAdapter|undefined; let testsEvents: (TestLoadStartedEvent|TestLoadFinishedEvent)[]; + let testsEventsConnection: vscode.Disposable; let testStatesEvents: (TestRunStartedEvent|TestRunFinishedEvent| TestSuiteEvent|TestEvent)[]; + let testStatesEventsConnection: vscode.Disposable; let spawnStub: any; let execFileStub: any; let fsWatchStub: any; let fsExistsStub: any; - const resetConfig = function(): Thenable { + function resetConfig(): Thenable { const packageJson = fse.readJSONSync( path.join(workspaceFolderUri.path, '../..', 'package.json')); const properties: {[prop: string]: any}[] = @@ -62,70 +305,89 @@ describe('C2TestAdapter', function() { }); }); return t; - }; + } - const createAdapterAndSubscribe = function() { - adapter = new myExtension.C2TestAdapter(workspaceFolder, logger); - testsEvents = []; - testStatesEvents = []; + function createAdapterAndSubscribe() { + adapter = new C2TestAdapter(workspaceFolder, logger); - disposable.push( + testsEvents = []; + testsEventsConnection = adapter.tests((e: TestLoadStartedEvent|TestLoadFinishedEvent) => { testsEvents.push(e); - })); - disposable.push(adapter.testStates( + }); + + testStatesEvents = []; + testStatesEventsConnection = adapter.testStates( (e: TestRunStartedEvent|TestRunFinishedEvent|TestSuiteEvent| TestEvent) => { testStatesEvents.push(e); - })); + }); + return adapter!; - }; + } - beforeEach(() => { - adapter = undefined; + function disposeAdapterAndSubscribers() { + testsEventsConnection.dispose(); + testStatesEventsConnection.dispose(); + testsEvents = []; + testStatesEvents = []; + } + + before(() => { fse.removeSync(dotVscodePath); + adapter = undefined; spawnStub = sinonSandbox.stub(child_process, 'spawn'); - spawnStub.throws(); - execFileStub = sinonSandbox.stub(child_process, 'execFile'); - execFileStub.throws(); - fsWatchStub = sinonSandbox.stub(fs, 'watch'); - fsWatchStub.throws(); - fsExistsStub = sinonSandbox.stub(fs, 'exists'); - fsExistsStub.throws(); + // reset config can cause problem with fse.removeSync(dotVscodePath); return resetConfig(); }); - afterEach(() => { - while (disposable.length > 0) disposable.pop()!.dispose(); + function resetStubs() { + spawnStub.reset(); + spawnStub.throws(); + execFileStub.reset(); + execFileStub.throws(); + fsWatchStub.reset(); + fsWatchStub.throws(); + fsExistsStub.reset(); + fsExistsStub.throws(); + } + + after(() => { + disposeAdapterAndSubscribers(); sinonSandbox.restore(); }); describe('detect config change', function() { - this.timeout(1000); - const waitForReloadAndAssert = () => { - const waitForReloadAndAssertInner = - (tryCount: number = 20): Promise => { - if (testsEvents.length < 2) - return new Promise(r => setTimeout(r, 10)) - .then(() => {waitForReloadAndAssertInner(tryCount - 1)}); - else { - assert.equal(testsEvents.length, 2); - assert.equal(testsEvents[0].type, 'started'); - assert.equal(testsEvents[1].type, 'finished'); - const suite = (testsEvents[1]).suite; - assert.notEqual(suite, undefined); - assert.equal(suite!.children.length, 0); - return Promise.resolve(); - } - }; - return waitForReloadAndAssertInner(); + this.slow(150); + + const waitForReloadAndAssert = (): Promise => { + const waitForReloadAndAssertInner = (tryCount: number): Promise => { + if (testsEvents.length < 2) + return new Promise(r => setTimeout(r, 10)) + .then(() => {waitForReloadAndAssertInner(tryCount - 1)}); + else { + assert.equal(testsEvents.length, 2); + assert.equal(testsEvents[0].type, 'started'); + assert.equal(testsEvents[1].type, 'finished'); + const suite = (testsEvents[1]).suite; + assert.notEqual(suite, undefined); + assert.equal(suite!.children.length, 0); + return Promise.resolve(); + } + }; + return waitForReloadAndAssertInner(20); }; + afterEach(() => { + disposeAdapterAndSubscribers(); + return resetConfig(); + }); + it('workerMaxNumber', () => { createAdapterAndSubscribe(); assert.deepEqual(testsEvents, []); @@ -165,12 +427,17 @@ describe('C2TestAdapter', function() { // describe('detect config change' describe('adapter:', () => { - let adapter: myExtension.C2TestAdapter; + let adapter: C2TestAdapter; beforeEach(() => { adapter = createAdapterAndSubscribe(); }); + afterEach(() => { + disposeAdapterAndSubscribers(); + resetStubs(); + }); + it('fill with empty config', function() { return adapter.load().then(() => { assert.equal(testsEvents.length, 2); @@ -182,75 +449,9 @@ describe('C2TestAdapter', function() { }); }); - describe('fill with example1', function() { + describe('example1', function() { let tests: any; - const randomnessXml = ``; - - const s1t1Xml = ` - - - `; - - const s1t2Xml = ` - - - - std::false_type::value - - - false - - - - ;`; - - const s1HeaderXml = ` - - - `; - - const s1Xml = s1HeaderXml + s1t1Xml + s1t2Xml + ` - - - - `; - - const s2t1Xml = ` - - - `; - - const s2t2Xml = ` - - - `; - - const s2t3Xml = ` - - - - std::false_type::value - - - false - - - - `; - - const s2HeaderXml = ` - - ` + - randomnessXml + ` - `; - - const s2Xml = s2HeaderXml + s2t1Xml + /* s2t2 is skipped */ s2t3Xml + ` - - - - `; - beforeEach(() => { return adapter.load() .then(() => { @@ -294,7 +495,7 @@ describe('C2TestAdapter', function() { spawnEvent.emit('close', 1); }); stdout.push( - s1HeaderXml + s1t1Xml + + example1.suite1.xmlHeader + example1.suite1.t1.xml + ` @@ -338,7 +539,7 @@ describe('C2TestAdapter', function() { spawnEvent.emit('close', 1); }); stdout.push( - s1HeaderXml + + example1.suite1.xmlHeader + ` @@ -373,7 +574,7 @@ describe('C2TestAdapter', function() { stdout.on('end', () => { spawnEvent.emit('close', 1); }); - stdout.push(s2HeaderXml + s2t2Xml + ` + stdout.push(example1.suite1.xmlHeader + example1.suite2.t2.xml + ` @@ -417,7 +618,7 @@ describe('C2TestAdapter', function() { spawnEvent.emit('close', 1); }); stdout.push( - s2HeaderXml + s2t3Xml + + example1.suite1.xmlHeader + example1.suite2.t3.xml + ` @@ -472,8 +673,10 @@ describe('C2TestAdapter', function() { tests.s1.execOptions) .returns(spawnEvent); - s2HeaderXml.split('\n').forEach((l: string) => {stdout.push(l)}); - s2t3Xml.split('\n').forEach((l: string) => {stdout.push(l)}); + example1.suite1.xmlHeader.split('\n').forEach( + (l: string) => {stdout.push(l)}); + example1.suite2.t3.xml.split('\n').forEach( + (l: string) => {stdout.push(l)}); stdout.push( ' \n'); stdout.push(' \n'); @@ -509,7 +712,7 @@ describe('C2TestAdapter', function() { stdout.on('end', () => { spawnEvent.emit('close', 1); }); - stdout.push(s1Xml); + stdout.push(example1.suite1.xmlFull); stdout.push(null); spawnStub @@ -554,7 +757,7 @@ describe('C2TestAdapter', function() { stdout.on('end', () => { spawnEvent.emit('close', 1); }); - stdout.push(s1Xml); + stdout.push(example1.suite1.xmlFull); stdout.push(null); spawnStub @@ -571,7 +774,7 @@ describe('C2TestAdapter', function() { stdout.on('end', () => { spawnEvent.emit('close', 1); }); - stdout.push(s2Xml); + stdout.push(example1.suite2.xmlFull); stdout.push(null); spawnStub @@ -710,9 +913,9 @@ describe('C2TestAdapter', function() { stdout.on('end', () => { spawnEvent.emit('close', 1); }); - const testCaseBegin = s1t1Xml.split('\n')[1]; + const testCaseBegin = example1.suite1.t1.xml.split('\n')[1]; assert.ok(testCaseBegin.indexOf(' { spawnEvent.emit('close', 1); }); - stdout.push(s1Xml); + stdout.push(example1.suite1.xmlFull); stdout.push(null); spawnStub @@ -777,7 +980,7 @@ describe('C2TestAdapter', function() { stdout.on('end', () => { spawnEvent.emit('close', 1); }); - stdout.push(s2Xml); + stdout.push(example1.suite2.xmlFull); stdout.push(null); spawnStub @@ -810,7 +1013,7 @@ describe('C2TestAdapter', function() { stdout.on('end', () => { spawnEvent.emit('close', 1); }); - stdout.push(s1Xml); + stdout.push(example1.suite1.xmlFull); stdout.push(null); spawnStub @@ -828,7 +1031,7 @@ describe('C2TestAdapter', function() { stdout.on('end', () => { spawnEvent.emit('close', 1); }); - stdout.push(s2Xml); + stdout.push(example1.suite2.xmlFull); stdout.push(null); spawnStub @@ -847,13 +1050,20 @@ describe('C2TestAdapter', function() { }); // it('cancel: after run finished' }); - // describe('fill with example1' + // describe('example1' }); // describe('adapter:' describe('executables:', function() { + this.slow(150); const cwd = path.join(process.cwd(), 'out', 'test'); + afterEach(() => { + disposeAdapterAndSubscribers(); + resetStubs(); + return resetConfig(); + }); + const updateAndVerify = (value: any, expected: any[]) => { return config.update('executables', value) .then(() => { @@ -931,66 +1141,8 @@ describe('C2TestAdapter', function() { }); // describe('executables:' - describe('load:', function() { - const cwd = path.join(process.cwd(), 'out', 'test'); - - const suite1TestList = `Matching test cases: - s1t1 - ../vscode-catch2-test-adapter/src/test/suite1.cpp:7 - tag1 - s1t2 - ../vscode-catch2-test-adapter/src/test/suite1.cpp:13 - tag1 -2 matching test cases - - `; - - const suite2TestList = `Matching test cases: - s2t1 - ../vscode-catch2-test-adapter/src/test/suite2.cpp:7 - tag1 - s2t2 - ../vscode-catch2-test-adapter/src/test/suite2.cpp:13 - tag1 - [.] - s2t3 - ../vscode-catch2-test-adapter/src/test/suite2.cpp:19 - tag1 -3 matching test cases - `; - - const updateAndLoad = (value: any) => { - return config.update('executables', value) - .then(() => { - const adapter = createAdapterAndSubscribe(); - - const watchEvents: Map = new Map(); - fsWatchStub.reset(); - fsWatchStub.callsFake((path: string) => { - const ee = new EventEmitter(); - watchEvents.set(path, ee); - return ee; - }); - - const verifyIsCatch2TestExecutable = - sinonSandbox.stub(adapter, 'verifyIsCatch2TestExecutable'); - verifyIsCatch2TestExecutable.returns(Promise.resolve(true)); - - return adapter.load().then(() => { - return watchEvents; - }); - }) - .then((watchEvents) => { - assert.equal(testsEvents.length, 2); - assert.equal(testsEvents[1].type, 'finished'); - assert.notEqual( - (testsEvents[1]).suite, undefined); - const root = (testsEvents[1]).suite!; - return {root: root, watchEvents: watchEvents}; - }); - }; - - function fakeExecFileFunc(pathAndContent: Map) { + context('example1', function() { + function fakeExecFileFunc(pathAndContent: Map) { return function( path: string, args: string[], cb: (err: any, stout: string, stderr: string) => void) { @@ -999,46 +1151,278 @@ describe('C2TestAdapter', function() { cb(new Error('fake file not exists.'), '', ''); } else if (args.length == 1 && args[0] === '--help') { cb(null, 'Catch v2.', ''); - } else if (!deepEqual(args, [ + } else if (deepEqual(args, [ '[.],*', '--verbosity', 'high', '--list-tests', '--use-colour', 'no' ])) { - assert.ok(false, inspect([path, args])); - } else { cb(null, res!, ''); + } else { + assert.ok(false, inspect([path, args])); }; }; }; - function fakeExistsFunc(pathAndContent: Map) { + function fakeExistsFunc(pathAndContent: Map) { return function(path: string, cb: (err: any, exists: boolean) => void) { cb(undefined, pathAndContent.has(path)); }; }; - const fakeFs = (pathAndContent: Iterable<[string, string]>) => { + function fakeSpawn() { + const testTestParams = ['--reporter', 'xml', '--durations', 'yes']; + + spawnStub + .withArgs( + example1.suite1.execPath, + [example1.suite1.t1.fullTestName, ...testTestParams]) + .callsFake(() => { + return new ChildProcessStub( + example1.suite1.xmlHeader + example1.suite1.t1.xml + + ''); + }); + spawnStub + .withArgs( + example1.suite1.execPath, + [example1.suite1.t2.fullTestName, ...testTestParams]) + .callsFake(() => { + return new ChildProcessStub( + example1.suite1.xmlHeader + example1.suite1.t2.xml + + ''); + }); + spawnStub.withArgs(example1.suite1.execPath, testTestParams) + .callsFake(() => { + return new ChildProcessStub(example1.suite1.xmlFull); + }); + + spawnStub + .withArgs( + example1.suite2.execPath, + [example1.suite2.t1.fullTestName, ...testTestParams]) + .callsFake(() => { + return new ChildProcessStub( + example1.suite2.xmlHeader + example1.suite2.t1.xml + + ''); + }); + spawnStub + .withArgs( + example1.suite2.execPath, + [example1.suite2.t2.fullTestName, ...testTestParams]) + .callsFake(() => { + return new ChildProcessStub( + example1.suite2.xmlHeader + example1.suite2.t2.xml + + ''); + }); + spawnStub + .withArgs( + example1.suite2.execPath, + [example1.suite2.t3.fullTestName, ...testTestParams]) + .callsFake(() => { + return new ChildProcessStub( + example1.suite2.xmlHeader + example1.suite2.t3.xml + + ''); + }); + spawnStub.withArgs(example1.suite2.execPath, testTestParams) + .callsFake(() => { + return new ChildProcessStub(example1.suite2.xmlFull); + }); + } + + function fakeFs(pathAndContent: Iterable<[string, string]>) { const map = new Map(pathAndContent); execFileStub.reset(); execFileStub.callsFake(fakeExecFileFunc(map)); + fsExistsStub.reset(); fsExistsStub.callsFake(fakeExistsFunc(map)); + + fsWatchStub.reset(); + fsWatchStub.callsFake((path: string) => { + if (map.has(path)) { + const ee = new class extends EventEmitter { + close() {} + }; + watchEvents.set(path, ee); + return ee; + } else { + throw Error('File not found?'); + } + }); + + fakeSpawn(); }; - it('"path1"', () => { - this.timeout(99999); - fakeFs([[path.join(cwd, 'path1'), suite1TestList]]); + const uniqueIdC = new Set(); + const watchEvents: Map = new Map(); + + before(() => { + fakeFs([ + [example1.suite1.execPath, example1.suite1.testList], + [example1.suite2.execPath, example1.suite2.testList] + ]); + }); + + beforeEach(() => { + watchEvents.clear(); + uniqueIdC.clear(); + }) + + after(() => { + resetStubs(); + }); + + context.only('load with config: executables="execPath1"', function() { + let adapter: TestAdapter; + let root: TestSuiteInfo; + + before(() => { + return config.update('executables', 'execPath1'); + }); + + beforeEach(async function() { + adapter = createAdapterAndSubscribe(); + await adapter.load(); + + assert.equal(testsEvents.length, 2, inspect(testsEvents)); + assert.equal(testsEvents[1].type, 'finished'); + assert.ok((testsEvents[1]).suite); + root = (testsEvents[1]).suite!; + + example1.assertWithoutChildren(root, uniqueIdC); + assert.equal(root.children.length, 1); + example1.suite1.assert(root.children[0], uniqueIdC); + }); + + afterEach(() => { + disposeAdapterAndSubscribers(); + }); + + after(() => { + return resetConfig(); + }); + + it('should run with not existing test id', async function() { + await adapter.run(['not existing id']); + + assert.deepEqual(testStatesEvents, [ + {type: 'started', tests: ['not existing id']}, + {type: 'finished'}, + ]); + }); - return updateAndLoad('path1').then((param) => { - assert.equal(param.root.children.length, 1); + it('should run s1t1 with success', async function() { + const suite1 = root.children[0]; + const s1t1 = suite1.children[0]; + + await adapter.run([s1t1.id]); + const expected = [ + {type: 'started', tests: [s1t1.id]}, + {type: 'suite', state: 'running', suite: suite1}, + {type: 'test', state: 'running', test: s1t1}, + { + type: 'test', + state: 'passed', + test: s1t1, + decorations: undefined, + message: 'Randomness seeded to: 2\nDuration: 0.000174 second(s)\n' + }, + {type: 'suite', state: 'completed', suite: suite1}, + {type: 'finished'}, + ]; + assert.deepEqual(testStatesEvents, expected); + + await adapter.run([s1t1.id]); + assert.deepEqual(testStatesEvents, [...expected, ...expected]); + }); + + it('should run suite1', async function() { + const suite1 = root.children[0]; + const s1t1 = suite1.children[0]; + const s1t2 = suite1.children[1]; + + await adapter.run([suite1.id]); + const expected = [ + {type: 'started', tests: [suite1.id]}, + {type: 'suite', state: 'running', suite: suite1}, + {type: 'test', state: 'running', test: s1t1}, + { + type: 'test', + state: 'passed', + test: s1t1, + decorations: undefined, + message: 'Randomness seeded to: 2\nDuration: 0.000174 second(s)\n' + }, + {type: 'test', state: 'running', test: s1t2}, + { + type: 'test', + state: 'failed', + test: s1t2, + decorations: [{line: 14, message: 'Expanded: false'}], + message: + 'Randomness seeded to: 2\nDuration: 0.000255 second(s)\n>>> s1t2(line: 13) REQUIRE (line: 15) \n Original:\n std::false_type::value\n Expanded:\n false\n<<<\n' + }, + {type: 'suite', state: 'completed', suite: suite1}, + {type: 'finished'}, + ]; + assert.deepEqual(testStatesEvents, expected); + + await adapter.run([suite1.id]); + assert.deepEqual(testStatesEvents, [...expected, ...expected]); }); }); - }); + }); // descibe('example1' }); // describe('C2TestAdapter' +describe.skip('a', function() { + this.timeout(99999); + + before(() => { + debugger; + }); + beforeEach(() => { + debugger; + }); + + after(() => { + debugger; + }); + afterEach(() => { + debugger; + }); + + it('a-it', () => { + debugger; + }); + + describe('b', () => { + before(() => { + debugger; + }); + beforeEach(() => { + debugger; + }); + + after(() => { + debugger; + }); + afterEach(() => { + debugger; + }); + + it('b-it1', () => { + debugger; + }); + + it('b-it2', () => { + debugger; + }); + }); +}); // fswatcher test aztan atiras vscode workspace watcherre // bonyolultabb teszteset parsoleasa de az mehet kulon fileba c2testinfo // mock getExecutables regex meg sima minden test // ExecutableConfig // execOptions -// writing xml \ No newline at end of file +// writing xml +// re-load soame object +// deepstrictequal \ No newline at end of file