Skip to content

refactor: 2.0 readiness #280

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 15 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions ava.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

module.exports = {
files: ['spec/**/*.ts'],
files: ['spec/**/*.spec.ts'],
typescript: {
compile: false,
rewritePaths: {
Expand All @@ -10,4 +10,4 @@ module.exports = {
cache: false,
failFast: true,
failWithoutAssertions: true
}
}
4 changes: 1 addition & 3 deletions compatibility-checks/test/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ type TestRunner = {

test.describe('Verifies test runner compatibility', () => {
const failingExec = (command: string): string => {
process.env
const { FORCE_COLOR, ...environment } = { ...process.env, CI: '1', NO_COLOR: '1' } as Partial<Record<string, string>>
try {
execSync(command, { env: environment, stdio: 'pipe' })
Expand Down Expand Up @@ -43,11 +42,10 @@ test.describe('Verifies test runner compatibility', () => {
`Could not find the expected failure location in the output. Expected "${testRunner.failureLocationText}"`
)
assert.ok(
result.includes('SubstituteException: Expected'),
result.includes('SubstituteException: Call count mismatch'),
`Could not find the expected exception message in the output: ${result}`
)
})
})
})
})

30 changes: 15 additions & 15 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@
"devDependencies": {
"@ava/typescript": "^3.0.1",
"@sinonjs/fake-timers": "^11.2.2",
"@types/node": "^18.19.22",
"@types/node": "^18.19.122",
"@types/sinonjs__fake-timers": "^8.1.5",
"ava": "^4.3.3",
"typescript": "^4.8.4"
"typescript": "^5.9.2"
},
"volta": {
"node": "18.19.1"
Expand Down
64 changes: 0 additions & 64 deletions spec/ClearSubstitute.spec.ts

This file was deleted.

4 changes: 2 additions & 2 deletions spec/RecordedArguments.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import test from 'ava'
import { inspect } from 'util'

import { Arg } from '../src'
import { RecordedArguments } from '../src/RecordedArguments'
import { RecordedArguments } from '../src/internals/RecordedArguments'

const testObject = { 'foo': 'bar' }
const testArray = ['a', 1, true]
Expand Down Expand Up @@ -135,4 +135,4 @@ test('generates custom text representation', t => {
t.is(inspect(RecordedArguments.from([])), '()')
t.is(inspect(RecordedArguments.from([undefined])), 'undefined')
t.is(inspect(RecordedArguments.from([undefined, 1])), '(undefined, 1)')
})
})
8 changes: 4 additions & 4 deletions spec/Recorder.spec.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import test from 'ava'

import { Recorder } from '../src/Recorder'
import { RecordsSet } from '../src/RecordsSet'
import { Substitute } from '../src/Substitute'
import { SubstituteNodeBase } from '../src/SubstituteNodeBase'
import { Recorder } from '../src/internals/Recorder'
import { RecordsSet } from '../src/internals/RecordsSet'
import { Substitute } from '../src/api/Substitute'
import { SubstituteNodeBase } from '../src/internals/SubstituteNodeBase'

const nodeFactory = (key: string) => {
const node = Substitute.for<SubstituteNodeBase>()
Expand Down
4 changes: 2 additions & 2 deletions spec/RecordsSet.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import test, { ExecutionContext } from 'ava'

import { RecordsSet } from '../src/RecordsSet'
import { RecordsSet } from '../src/internals/RecordsSet'

const dataArray = [1, 2, 3]
function* dataArrayGenerator() {
Expand Down Expand Up @@ -63,4 +63,4 @@ test('applies and preserves the order of filter and map functions everytime the
t.deepEqual([...setWithFilter], [1, 3])
t.deepEqual([...setWithFilterAndMap], ['1', '3'])
t.deepEqual([...setWithFilterMapAndAnotherFilter], ['3'])
})
})
4 changes: 2 additions & 2 deletions spec/regression/Arguments.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import test from 'ava'
import { Arg } from '../../src'
import { Argument } from '../../src/Arguments'
import { Argument } from '../../src/shared'

const testObject = { "foo": "bar" }
const testArray = ["a", 1, true]
Expand Down Expand Up @@ -107,4 +107,4 @@ test('should not match the argument with the predicate function using Arg.is.not

t.true(Arg.is.not<string>(x => x === 'foo').matches('bar'))
t.true(Arg.is.not<number>(x => x % 2 == 0).matches(3))
})
})
28 changes: 28 additions & 0 deletions spec/regression/clearReceivedCalls.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import test from 'ava'

import { Substitute, SubstituteOf, clearReceivedCalls } from '../../src'
import { SubstituteNode, instance } from '../../src/internals/SubstituteNode'

interface Calculator {
add(a: number, b: number): number
subtract(a: number, b: number): number
divide(a: number, b: number): number
isEnabled: boolean
}

type InstanceReturningSubstitute<T> = SubstituteOf<T> & {
[instance]: SubstituteNode
}

test('clears received calls on a substitute', t => {
const calculator = Substitute.for<Calculator>() as InstanceReturningSubstitute<Calculator>
calculator.add(1, 1)
calculator.add(1, 1).returns(2)
calculator[clearReceivedCalls]();

t.is(calculator[instance].recorder.records.size, 2)
t.is(calculator[instance].recorder.indexedRecords.size, 2)

t.throws(() => calculator.received().add(1, 1))
t.is(2, calculator.add(1, 1))
})
6 changes: 3 additions & 3 deletions spec/regression/didNotReceive.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import test from 'ava'
import { Substitute, Arg } from '../../src'
import { SubstituteException } from '../../src/SubstituteException'
import { SubstituteException } from '../../src/internals/SubstituteException'

interface Calculator {
add(a: number, b: number): number
Expand All @@ -13,7 +13,7 @@ test('not calling a method correctly asserts the call count', t => {
const calculator = Substitute.for<Calculator>()

calculator.didNotReceive().add(1, 1)
t.throws(() => calculator.received(1).add(1, 1), { instanceOf: SubstituteException })
t.throws(() => calculator.received().add(1, 1), { instanceOf: SubstituteException })
t.throws(() => calculator.received().add(Arg.all()), { instanceOf: SubstituteException })
})

Expand Down Expand Up @@ -49,4 +49,4 @@ test('not getting a property with mock correctly asserts the call count', t => {
calculator.didNotReceive().isEnabled
t.throws(() => calculator.received(1).isEnabled, { instanceOf: SubstituteException })
t.throws(() => calculator.received().isEnabled, { instanceOf: SubstituteException })
})
})
Loading