-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from nearform/a02-verify
Add verify feature to the workshop
- Loading branch information
Showing
26 changed files
with
553 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
import { test } from '../../../verify/test.verify.js' | ||
import { assertCalls } from '../../../verify/assert.verify.js' | ||
import { sum, sumAsync } from './index.verify.js' | ||
|
||
await import('../test/index.test.js') | ||
|
||
// I'm creating this wrapper in order to be able to spy the process.exit | ||
process.on('exit', () => { | ||
console.log('Validating the test completion...') | ||
|
||
const expectations = [ | ||
{ | ||
condition: test.mock.calls.length < 2, | ||
message: | ||
'You need to create a test for both the sum and sumAsync functions' | ||
}, | ||
{ | ||
condition: | ||
typeof assertCalls.find( | ||
a => a.testName === 'sum' && a.method === 'deepStrictEqual' | ||
) === 'undefined', | ||
message: 'You need to call "deepStrictEqual" inside the "sum" test' | ||
}, | ||
{ | ||
condition: | ||
typeof assertCalls.find( | ||
a => a.testName === 'sum' && a.method === 'ok' | ||
) === 'undefined', | ||
message: 'You need to call "ok" inside the "sum" test' | ||
}, | ||
{ | ||
condition: | ||
typeof assertCalls.find( | ||
a => a.testName === 'sum' && a.method === 'doesNotThrow' | ||
) === 'undefined', | ||
message: 'You need to call "doesNotThrow" inside the "sum" test' | ||
}, | ||
{ | ||
condition: | ||
typeof assertCalls.find( | ||
a => a.testName === 'sum' && a.method === 'throws' | ||
) === 'undefined', | ||
message: 'You need to call "throws" inside the "sum" test' | ||
}, | ||
{ | ||
condition: | ||
typeof assertCalls.find( | ||
a => a.testName === 'sumAsync' && a.method === 'deepStrictEqual' | ||
) === 'undefined', | ||
message: 'You need to call "deepStrictEqual" inside the "sumAsync" test' | ||
}, | ||
{ | ||
condition: | ||
typeof assertCalls.find( | ||
a => a.testName === 'sumAsync' && a.method === 'ok' | ||
) === 'undefined', | ||
message: 'You need to call "ok" inside the "sumAsync" test' | ||
}, | ||
{ | ||
condition: | ||
typeof assertCalls.find( | ||
a => a.testName === 'sumAsync' && a.method === 'doesNotReject' | ||
) === 'undefined', | ||
message: 'You need to call "doesNotReject" inside the "sumAsync" test' | ||
}, | ||
{ | ||
condition: | ||
typeof assertCalls.find( | ||
a => a.testName === 'sumAsync' && a.method === 'rejects' | ||
) === 'undefined', | ||
message: 'You need to call "rejects" inside the "sumAsync" test' | ||
}, | ||
{ | ||
condition: sum.mock.calls.length < 1, | ||
message: 'You need to call "sum" at least once in your test' | ||
}, | ||
{ | ||
condition: sumAsync.mock.calls.length < 1, | ||
message: 'You need to call "sumAsync" at least once in your test' | ||
} | ||
] | ||
|
||
for (const expectation of expectations) { | ||
if (expectation.condition) throw new Error(expectation.message) | ||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { | ||
sum as originalSum, | ||
sumAsync as originalSumAsync | ||
} from '../src/index.js' | ||
import { mock } from 'node:test' | ||
|
||
export const sum = mock.fn(originalSum) | ||
export const sumAsync = mock.fn(originalSumAsync) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { test } from '../../../verify/test.verify.js' | ||
import { fnCalls } from './index.verify.js' | ||
|
||
await import('../test/index.test.js') | ||
|
||
// I'm creating this wrapper in order to be able to spy the process.exit | ||
process.on('exit', () => { | ||
console.log('Validating the test completion...') | ||
|
||
const expectations = [ | ||
{ | ||
condition: test.mock.calls.length < 3, | ||
message: 'You need to create a test for at least three cases' | ||
}, | ||
{ | ||
condition: | ||
typeof fnCalls.find( | ||
call => call.name === 'connectToDatabase' && call.caller === 'before' | ||
) === 'undefined', | ||
message: 'You need to call "connectToDatabase" inside a "before" hook' | ||
}, | ||
{ | ||
condition: | ||
typeof fnCalls.find( | ||
call => call.name === 'createUser' && call.caller === 'beforeEach' | ||
) === 'undefined', | ||
message: 'You need to call "createUser" inside a "beforeEach" hook' | ||
}, | ||
{ | ||
condition: | ||
typeof fnCalls.find( | ||
call => call.name === 'deleteUser' && call.caller === 'afterEach' | ||
) === 'undefined', | ||
message: 'You need to call "deleteUser" inside a "afterEach" hook' | ||
}, | ||
{ | ||
condition: | ||
typeof fnCalls.find( | ||
call => | ||
call.name === 'closeDatabaseConnection' && call.caller === 'after' | ||
) === 'undefined', | ||
message: | ||
'You need to call "closeDatabaseConnection" inside a "after" hook' | ||
} | ||
] | ||
|
||
for (const expectation of expectations) { | ||
if (expectation.condition) throw new Error(expectation.message) | ||
} | ||
}) |
Oops, something went wrong.