Skip to content

Commit b31b217

Browse files
refactor: 2.0 readiness (#280)
* feat: introduce symbols * fix: progress on new syntax * fix: progress on symbols * feat: symbols for methods - removed Substitute.disableFor * refactor: import path alignment * refactor: symbols only when needed * refac: use symbols for context handling * fix: update compatibility assertion * fix: update test import * fix: use symbol representation on clear method * test: add overlapping interface regression --------- Co-authored-by: Enrique Pöhlmann <[email protected]>
1 parent 30c69d9 commit b31b217

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+795
-595
lines changed

ava.config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22
module.exports = {
3-
files: ['spec/**/*.ts'],
3+
files: ['spec/**/*.spec.ts'],
44
typescript: {
55
compile: false,
66
rewritePaths: {
@@ -10,4 +10,4 @@ module.exports = {
1010
cache: false,
1111
failFast: true,
1212
failWithoutAssertions: true
13-
}
13+
}

compatibility-checks/test/index.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ type TestRunner = {
1010

1111
test.describe('Verifies test runner compatibility', () => {
1212
const failingExec = (command: string): string => {
13-
process.env
1413
const { FORCE_COLOR, ...environment } = { ...process.env, CI: '1', NO_COLOR: '1' } as Partial<Record<string, string>>
1514
try {
1615
execSync(command, { env: environment, stdio: 'pipe' })
@@ -43,11 +42,10 @@ test.describe('Verifies test runner compatibility', () => {
4342
`Could not find the expected failure location in the output. Expected "${testRunner.failureLocationText}"`
4443
)
4544
assert.ok(
46-
result.includes('SubstituteException: Expected'),
45+
result.includes('SubstituteException: Call count mismatch'),
4746
`Could not find the expected exception message in the output: ${result}`
4847
)
4948
})
5049
})
5150
})
5251
})
53-

package-lock.json

Lines changed: 15 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,10 @@
4646
"devDependencies": {
4747
"@ava/typescript": "^3.0.1",
4848
"@sinonjs/fake-timers": "^11.2.2",
49-
"@types/node": "^18.19.22",
49+
"@types/node": "^18.19.122",
5050
"@types/sinonjs__fake-timers": "^8.1.5",
5151
"ava": "^4.3.3",
52-
"typescript": "^4.8.4"
52+
"typescript": "^5.9.2"
5353
},
5454
"volta": {
5555
"node": "18.19.1"

spec/ClearSubstitute.spec.ts

Lines changed: 0 additions & 64 deletions
This file was deleted.

spec/RecordedArguments.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import test from 'ava'
22
import { inspect } from 'util'
33

44
import { Arg } from '../src'
5-
import { RecordedArguments } from '../src/RecordedArguments'
5+
import { RecordedArguments } from '../src/internals/RecordedArguments'
66

77
const testObject = { 'foo': 'bar' }
88
const testArray = ['a', 1, true]
@@ -135,4 +135,4 @@ test('generates custom text representation', t => {
135135
t.is(inspect(RecordedArguments.from([])), '()')
136136
t.is(inspect(RecordedArguments.from([undefined])), 'undefined')
137137
t.is(inspect(RecordedArguments.from([undefined, 1])), '(undefined, 1)')
138-
})
138+
})

spec/Recorder.spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import test from 'ava'
22

3-
import { Recorder } from '../src/Recorder'
4-
import { RecordsSet } from '../src/RecordsSet'
5-
import { Substitute } from '../src/Substitute'
6-
import { SubstituteNodeBase } from '../src/SubstituteNodeBase'
3+
import { Recorder } from '../src/internals/Recorder'
4+
import { RecordsSet } from '../src/internals/RecordsSet'
5+
import { Substitute } from '../src/api/Substitute'
6+
import { SubstituteNodeBase } from '../src/internals/SubstituteNodeBase'
77

88
const nodeFactory = (key: string) => {
99
const node = Substitute.for<SubstituteNodeBase>()

spec/RecordsSet.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import test, { ExecutionContext } from 'ava'
22

3-
import { RecordsSet } from '../src/RecordsSet'
3+
import { RecordsSet } from '../src/internals/RecordsSet'
44

55
const dataArray = [1, 2, 3]
66
function* dataArrayGenerator() {
@@ -63,4 +63,4 @@ test('applies and preserves the order of filter and map functions everytime the
6363
t.deepEqual([...setWithFilter], [1, 3])
6464
t.deepEqual([...setWithFilterAndMap], ['1', '3'])
6565
t.deepEqual([...setWithFilterMapAndAnotherFilter], ['3'])
66-
})
66+
})

spec/regression/Arguments.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import test from 'ava'
22
import { Arg } from '../../src'
3-
import { Argument } from '../../src/Arguments'
3+
import { Argument } from '../../src/shared'
44

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

108108
t.true(Arg.is.not<string>(x => x === 'foo').matches('bar'))
109109
t.true(Arg.is.not<number>(x => x % 2 == 0).matches(3))
110-
})
110+
})
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import test from 'ava'
2+
3+
import { Substitute, SubstituteOf, clearReceivedCalls } from '../../src'
4+
import { SubstituteNode, instance } from '../../src/internals/SubstituteNode'
5+
6+
interface Calculator {
7+
add(a: number, b: number): number
8+
subtract(a: number, b: number): number
9+
divide(a: number, b: number): number
10+
isEnabled: boolean
11+
}
12+
13+
type InstanceReturningSubstitute<T> = SubstituteOf<T> & {
14+
[instance]: SubstituteNode
15+
}
16+
17+
test('clears received calls on a substitute', t => {
18+
const calculator = Substitute.for<Calculator>() as InstanceReturningSubstitute<Calculator>
19+
calculator.add(1, 1)
20+
calculator.add(1, 1).returns(2)
21+
calculator[clearReceivedCalls]();
22+
23+
t.is(calculator[instance].recorder.records.size, 2)
24+
t.is(calculator[instance].recorder.indexedRecords.size, 2)
25+
26+
t.throws(() => calculator.received().add(1, 1))
27+
t.is(2, calculator.add(1, 1))
28+
})

0 commit comments

Comments
 (0)