-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
4,167 additions
and
544 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
import { expect } from 'chai' | ||
import { describe, it } from 'vitest' | ||
|
||
import equal from './equal.js' | ||
|
||
|
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,38 @@ | ||
import { Suite, TestFunction, describe, it } from 'vitest' | ||
|
||
let prevKeyword: 'Given' | 'Then' = 'Given' | ||
|
||
type SuiteFunction = (this: Suite) => void | ||
|
||
export const Feature = (message: string, fn: SuiteFunction) => | ||
describe(`Feature: ${message}`, fn) | ||
|
||
export const Scenario = (message: string, fn: SuiteFunction) => { | ||
describe(`Scenario: ${message}`, fn) | ||
prevKeyword = 'Given' | ||
} | ||
|
||
export const Given = (message: string, fn: SuiteFunction) => { | ||
describe(`Given ${message}`, fn) | ||
prevKeyword = 'Given' | ||
} | ||
|
||
export const When = (message: string, fn: SuiteFunction) => describe(`When ${message}`, fn) | ||
|
||
export const Then = (message: string, fn: TestFunction) => { | ||
it(`Then ${message}`, fn) | ||
prevKeyword = 'Then' | ||
} | ||
|
||
export const And = (message: string, fn: TestFunction | SuiteFunction) => { | ||
switch (prevKeyword) { | ||
case 'Given': | ||
describe(`And ${message}`, fn as SuiteFunction) | ||
break | ||
case 'Then': | ||
it(`And ${message}`, fn as TestFunction) | ||
break | ||
default: | ||
throw new Error(`Unexpected previous keyword for And call: ${prevKeyword}`) | ||
} | ||
} |
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,48 @@ | ||
import { Assertion } from 'chai' | ||
|
||
import { TwoDimensionalArray } from '../lib/two-dimenisonal-array.js' | ||
import equal from '../lib/util/equal.js' | ||
|
||
Assertion.overwriteMethod('equal', (_super) => { | ||
return function (this: typeof Assertion, ...args: unknown[]) { | ||
const obj = this._obj | ||
|
||
if (obj instanceof TwoDimensionalArray && obj instanceof TwoDimensionalArray) { | ||
const other = args[0] as TwoDimensionalArray | ||
this.assert( | ||
obj.equals(other), | ||
`expected ${obj} to equal ${other}`, | ||
`expected ${obj} to not equal ${other}`, | ||
obj, | ||
other, | ||
true | ||
) | ||
} else { | ||
_super.apply(this, args) | ||
} | ||
} | ||
}) | ||
|
||
Assertion.addMethod('approxEqual', function (this: typeof Assertion, other: number) { | ||
const value = this._obj | ||
this.assert( | ||
equal(value, other), | ||
`expected ${value} to be approximately equal to ${other}`, | ||
`expected ${value} to not be approximately equal to ${other}`, | ||
value, | ||
other | ||
) | ||
}) | ||
|
||
declare global { | ||
export namespace Chai { | ||
interface Assertion { | ||
/** | ||
* Asserts that the other number is approximately equal to the given number, given the | ||
* EPSILON value defined in equal.ts. | ||
* @param other The other number to compare to. | ||
*/ | ||
approxEqual(other: number): Assertion | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
{ | ||
"extends": "./tsconfig.json", | ||
"exclude": ["src/www", "src/**/*.spec.ts"] | ||
"exclude": ["src/**/*.spec.ts", "./*.ts", "src/test/**/*.ts"] | ||
} |
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,16 @@ | ||
import { coverageConfigDefaults, defineConfig } from 'vitest/config' | ||
|
||
export default defineConfig({ | ||
test: { | ||
browser: { | ||
name: 'chrome', | ||
enabled: true, | ||
headless: true, | ||
}, | ||
coverage: { | ||
enabled: true, | ||
exclude: ['dist/**/*', 'wasm/**/*', ...coverageConfigDefaults.exclude], | ||
provider: 'istanbul', | ||
}, | ||
}, | ||
}) |