Skip to content

Commit 123eed6

Browse files
refac: use symbols for context handling
1 parent b1add0e commit 123eed6

Some content is hidden

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

43 files changed

+621
-524
lines changed

package-lock.json

Lines changed: 14 additions & 14 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": "^5.4.2"
52+
"typescript": "^5.9.2"
5353
},
5454
"volta": {
5555
"node": "18.19.1"

spec/ClearSubstitute.spec.ts

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

3-
import { Substitute, SubstituteOf, clearReceivedCalls, received, returns } from '../src'
4-
import { SubstituteNode, instance } from '../src/SubstituteNode'
3+
import { Substitute, SubstituteOf } from '../src'
4+
import { SubstituteNode, instance } from '../src/internals/SubstituteNode'
55

66
interface Calculator {
77
add(a: number, b: number): number
@@ -14,7 +14,7 @@ type InstanceReturningSubstitute<T> = SubstituteOf<T> & {
1414
[instance]: SubstituteNode
1515
}
1616

17-
test('clears received calls on a substitute', t => {
17+
test.skip('clears received calls on a substitute', t => {
1818
const calculator = Substitute.for<Calculator>() as InstanceReturningSubstitute<Calculator>
1919
calculator.add(1, 1)
2020
calculator.add(1, 1).returns(2)
@@ -25,4 +25,4 @@ test('clears received calls on a substitute', t => {
2525

2626
t.throws(() => calculator.received().add(1, 1))
2727
t.is(2, calculator.add(1, 1))
28-
})
28+
})

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 & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +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'
7-
import { returns } from '../src'
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'
87

98
const nodeFactory = (key: string) => {
109
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/didNotReceive.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import test from 'ava'
2-
import { Substitute, Arg, didNotReceive, received, returns } from '../../src'
3-
import { SubstituteException } from '../../src/SubstituteException'
2+
import { Substitute, Arg } from '../../src'
3+
import { SubstituteException } from '../../src/internals/SubstituteException'
44

55
interface Calculator {
66
add(a: number, b: number): number
@@ -49,4 +49,4 @@ test('not getting a property with mock correctly asserts the call count', t => {
4949
calculator.didNotReceive().isEnabled
5050
t.throws(() => calculator.received(1).isEnabled, { instanceOf: SubstituteException })
5151
t.throws(() => calculator.received().isEnabled, { instanceOf: SubstituteException })
52-
})
52+
})

spec/regression/index.test.ts

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

3-
import { Substitute, Arg, SubstituteOf, received, mimicks, resolves, returns } from '../../src'
3+
import { Substitute, Arg, SubstituteOf, received } from '../../src'
44

55
class Dummy {
66

@@ -116,16 +116,16 @@ test('class method received', t => {
116116
`Expected to receive 7 method calls matching c('hi', 'there'), but received 4.\n` +
117117
'All property or method calls to @Substitute.c received so far:\n' +
118118
`› ✔ @Substitute.c('hi', 'there')\n` +
119-
` called at <anonymous> (${process.cwd()}/spec/regression/index.test.ts:114:18)\n` +
119+
` called at <anonymous> (${process.cwd()}/spec/regression/index.test.ts:105:18)\n` +
120120
`› ✘ @Substitute.c('hi', 'the1re')\n` +
121-
` called at <anonymous> (${process.cwd()}/spec/regression/index.test.ts:115:18)\n` +
121+
` called at <anonymous> (${process.cwd()}/spec/regression/index.test.ts:106:18)\n` +
122122
`› ✔ @Substitute.c('hi', 'there')\n` +
123-
` called at <anonymous> (${process.cwd()}/spec/regression/index.test.ts:116:18)\n` +
123+
` called at <anonymous> (${process.cwd()}/spec/regression/index.test.ts:107:18)\n` +
124124
`› ✔ @Substitute.c('hi', 'there')\n` +
125-
` called at <anonymous> (${process.cwd()}/spec/regression/index.test.ts:117:18)\n` +
125+
` called at <anonymous> (${process.cwd()}/spec/regression/index.test.ts:108:18)\n` +
126126
`› ✔ @Substitute.c('hi', 'there')\n` +
127-
` called at <anonymous> (${process.cwd()}/spec/regression/index.test.ts:118:18)\n`
128-
const { message } = t.throws(() => { substitute.received(7).c('hi', 'there') })
127+
` called at <anonymous> (${process.cwd()}/spec/regression/index.test.ts:109:18)\n`
128+
const { message } = t.throws(() => { substitute[received](7).c('hi', 'there') })
129129
t.is(message.replace(textModifierRegex, ''), expectedMessage)
130130
})
131131

@@ -143,8 +143,8 @@ test('received call matches after partial mocks using property instance mimicks'
143143
`Expected to receive 2 method calls matching c('lala', 'bar'), but received 1.\n` +
144144
'All property or method calls to @Substitute.c received so far:\n' +
145145
`› ✔ @Substitute.c('lala', 'bar')\n` +
146-
` called at <anonymous> (${process.cwd()}/spec/regression/index.test.ts:145:13)\n`
147-
const { message } = t.throws(() => substitute.received(2).c('lala', 'bar'))
146+
` called at <anonymous> (${process.cwd()}/spec/regression/index.test.ts:136:13)\n`
147+
const { message } = t.throws(() => substitute[received](2).c('lala', 'bar'))
148148
t.is(message.replace(textModifierRegex, ''), expectedMessage)
149149
t.deepEqual(substitute.d, 1337)
150150
})

spec/regression/issues/178.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import test, { ExecutionContext, ThrowsExpectation } from 'ava'
22
import * as fakeTimers from '@sinonjs/fake-timers'
33
import { types } from 'util'
44

5-
import { Substitute, didNotReceive, received, returns } from '../../../src'
6-
import { SubstituteException } from '../../../src/SubstituteException'
5+
import { Substitute } from '../../../src'
6+
import { SubstituteException } from '../../../src/internals/SubstituteException'
77

88
interface Library {
99
subSection: Subsection

spec/regression/received.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import test from 'ava'
2-
import { Substitute, Arg, received, returns } from '../../src'
3-
import { SubstituteException } from '../../src/SubstituteException'
2+
import { Substitute, Arg } from '../../src'
3+
import { SubstituteException } from '../../src/internals/SubstituteException'
44

55
interface Calculator {
66
add(a: number, b: number): number
@@ -137,4 +137,4 @@ test('calling a method does not interfere with other properties or methods call
137137

138138
t.throws(() => calculator.received().multiply(1, 1), { instanceOf: SubstituteException })
139139
t.throws(() => calculator.received().multiply(Arg.all()), { instanceOf: SubstituteException })
140-
})
140+
})

0 commit comments

Comments
 (0)