From 6e84f13145ef3547918eb9f7aa1a7b19d72786ed Mon Sep 17 00:00:00 2001 From: ivojawer Date: Fri, 7 Jun 2024 01:33:24 -0300 Subject: [PATCH] fix describe + tests --- src/commands/test.ts | 2 +- test/test.test.ts | 33 +++++++++++++++++++++++++++++---- 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/src/commands/test.ts b/src/commands/test.ts index a50394e..919272d 100644 --- a/src/commands/test.ts +++ b/src/commands/test.ts @@ -60,7 +60,7 @@ function getBaseNode(environment: Environment, filter: string | undefined, optio if(!nodeToFilter) throw new TestSearchMissError(`File '${file}' not found`) } if (describe) { - nodeToFilter = nodeToFilter.descendants.find(node => node.is(Describe) && node.name === `"${describe}"`) as Describe | undefined ?? nodeToFilter + nodeToFilter = nodeToFilter.descendants.find(node => node.is(Describe) && node.name === `"${describe}"`) as Describe | undefined if(!nodeToFilter) throw new TestSearchMissError(`Describe '${describe}' not found`) } return nodeToFilter diff --git a/test/test.test.ts b/test/test.test.ts index 8f0c2f2..f197fa7 100644 --- a/test/test.test.ts +++ b/test/test.test.ts @@ -1,11 +1,11 @@ import { expect } from 'chai' +import logger from 'loglevel' import { join } from 'path' -import { buildEnvironmentForProject } from '../src/utils' -import test, { getTarget, sanitize, tabulationForNode, validateParameters } from '../src/commands/test' +import sinon from 'sinon' import { Environment } from 'wollok-ts' -import logger from 'loglevel' +import test, { getTarget, sanitize, tabulationForNode, validateParameters } from '../src/commands/test' import { logger as fileLogger } from '../src/logger' -import sinon from 'sinon' +import { buildEnvironmentForProject } from '../src/utils' import { spyCalledWithSubstring } from './assertions' describe('Test', () => { @@ -265,6 +265,7 @@ describe('Test', () => { let fileLoggerInfoSpy: sinon.SinonStub let loggerInfoSpy: sinon.SinonStub + let loggerErrorSpy: sinon.SinonStub let processExitSpy: sinon.SinonStub const projectPath = join('examples', 'test-examples', 'normal-case') @@ -281,6 +282,7 @@ describe('Test', () => { loggerInfoSpy = sinon.stub(logger, 'info') fileLoggerInfoSpy = sinon.stub(fileLogger, 'info') processExitSpy = sinon.stub(process, 'exit') + loggerErrorSpy = sinon.stub(logger, 'error') }) afterEach(() => { @@ -301,6 +303,29 @@ describe('Test', () => { expect(fileLoggerInfoSpy.firstCall.firstArg.result).to.deep.equal({ ok: 3, failed: 0 }) }) + it('passing a wrong filename runs no tests and logs a warning', async () => { + await test(undefined, { + ...emptyOptions, + file: 'non-existing-file.wtest', + }) + + expect(processExitSpy.callCount).to.equal(0) + expect(spyCalledWithSubstring(loggerInfoSpy, 'Running 0 tests')).to.be.true + expect(spyCalledWithSubstring(loggerErrorSpy, 'File \'non-existing-file.wtest\' not found')).to.be.true + }) + + it('passing a wrong describe runs no tests and logs a warning', async () => { + await test(undefined, { + ...emptyOptions, + file: 'test-one.wtest', + describe: 'non-existing-describe', + }) + + expect(processExitSpy.callCount).to.equal(0) + expect(spyCalledWithSubstring(loggerInfoSpy, 'Running 0 tests')).to.be.true + expect(spyCalledWithSubstring(loggerErrorSpy, 'Describe \'non-existing-describe\' not found')).to.be.true + }) + it('returns exit code 2 if one or more tests fail', async () => { await test(undefined, emptyOptions)