Skip to content

Commit 92268f5

Browse files
committed
Replace a barrel file's re-export in the Babel example
Babel compiles `export { square } from './squarer'` to a getter, which td.replace(path) used to imitate as `undefined`. This runs that path through a real compiler in CI.
1 parent 769ea69 commit 92268f5

4 files changed

Lines changed: 19 additions & 1 deletion

File tree

‎examples/babel/lib/calculator.js‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import Adder from './adder'
22
import Subtractor from './subtractor'
33
import Multiplier from './multiplier'
44
import divider from './divider'
5+
import { square } from './operations'
56

67
export default class Calculator {
78
calculate(operation, ...operands) {
@@ -16,6 +17,8 @@ export default class Calculator {
1617
divider.numerator.set(operands[0])
1718
divider.otherOptions.divisor.setThatToo(operands[1])
1819
return new divider.ohAndAlso.Executor().execute()
20+
case 'square':
21+
return square(operands[0])
1922
}
2023
}
2124
}

‎examples/babel/lib/operations.js‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// Babel compiles re-exports like this one to getters
2+
export { square } from './squarer'

‎examples/babel/lib/squarer.js‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export function square (n) {
2+
throw 'not implemented!'
3+
}

‎examples/babel/test/lib/calculator-test.js‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import assert from 'assert'
22
import { describe, it, beforeEach, afterEach } from 'node:test'
33
import { td, setup, teardown } from '../helper'
44

5-
let subject, Adder, Subtractor, Multiplier, divider, result
5+
let subject, Adder, Subtractor, Multiplier, divider, operations, result
66
describe('Calculator', () => {
77
describe('#calculate', () => {
88
beforeEach(() => {
@@ -12,6 +12,7 @@ describe('Calculator', () => {
1212
Subtractor = td.replace('../../lib/subtractor')
1313
Multiplier = td.replace('../../lib/multiplier').default
1414
divider = td.replace('../../lib/divider').default
15+
operations = td.replace('../../lib/operations')
1516
const Calculator = require('../../lib/calculator').default
1617
subject = new Calculator()
1718
})
@@ -55,5 +56,14 @@ describe('Calculator', () => {
5556
td.verify(divider.otherOptions.divisor.setThatToo(2))
5657
assert.equal(result, 'lol')
5758
})
59+
60+
it('delegates to a squarer re-exported from a barrel file', () => {
61+
assert.equal(td.explain(operations.square).isTestDouble, true)
62+
td.when(operations.square(3)).thenReturn('squared math!')
63+
64+
result = subject.calculate('square', 3)
65+
66+
assert.equal(result, 'squared math!')
67+
})
5868
})
5969
})

0 commit comments

Comments
 (0)