Skip to content

Commit

Permalink
fix describe + tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ivojawer committed Jun 7, 2024
1 parent 518de98 commit 6e84f13
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/commands/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
33 changes: 29 additions & 4 deletions test/test.test.ts
Original file line number Diff line number Diff line change
@@ -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', () => {
Expand Down Expand Up @@ -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')
Expand All @@ -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(() => {
Expand All @@ -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)

Expand Down

0 comments on commit 6e84f13

Please sign in to comment.