-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
mocha functioning in browser, jest in client.
- Loading branch information
1 parent
b4c28cb
commit 9c80a76
Showing
15 changed files
with
289 additions
and
153 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
//rules for markdown lint: https://github.com/DavidAnson/vscode-markdownlint#configure | ||
{ | ||
"default": true, | ||
"MD013": { //line-length | ||
"line_length": 200 | ||
}, | ||
"MD025": false | ||
} |
File renamed without changes.
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/* eslint-disable @typescript-eslint/ban-types */ | ||
|
||
declare type ANY = typeof any | ||
declare function describe( name: string, fn: Function ) | ||
declare function it( name: string, fn?: ( cb: IDoneCallback ) => ANY, timeout?: number ): void; | ||
|
||
|
||
interface IDoneCallback { | ||
( ...args: ANY[] ): ANY; | ||
//fail( error?: string | { message: string } ): ANY; | ||
} |
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,13 @@ | ||
|
||
|
||
|
||
|
||
|
||
|
||
if ( globalThis.describe == null ) { | ||
globalThis.describe = () => { } | ||
} | ||
if ( globalThis.it == null ) { | ||
globalThis.it = () => { } | ||
} | ||
|
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,87 @@ | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
/* eslint-disable dot-notation */ | ||
//entrypoint into all tests. | ||
|
||
|
||
/** see: https://webpack.js.org/guides/dependency-management/#requirecontext */ | ||
declare interface IRequireContextResolve { | ||
resolve: ( key: string ) => string; | ||
keys: () => string[]; | ||
id: string; | ||
|
||
/** A context module exports a (require) function that takes one argument: the request. */ | ||
( path: string ): never | ||
} | ||
|
||
// eslint-disable-next-line @typescript-eslint/naming-convention | ||
declare interface NodeRequire { | ||
/** for running in a browser viw webpack + mocha-loader. | ||
* @remarks | ||
* see: https://github.com/webpack-contrib/mocha-loader and https://webpack.js.org/guides/dependency-management/#requirecontext | ||
*/ | ||
context: ( directory: string, useSubdirectories?: boolean, regExp?: RegExp, mode?: string ) => IRequireContextResolve | ||
} | ||
|
||
|
||
|
||
|
||
//bootstrap mocha, as per: https://mochajs.org/#running-mocha-in-the-browser | ||
//import expect from "expect" | ||
//if(globalThis.expect ==null) | ||
// if ( typeof ( expect ) === "undefined" ) { | ||
// window[ "expect" ] = require( "chai" ) | ||
// } | ||
const mocha = require( "mocha" ) | ||
//import "mocha" | ||
mocha.setup( "bdd" ) | ||
mocha.growl() // enable web notification | ||
|
||
|
||
|
||
|
||
//import * as chai from "chai-as-promised" | ||
|
||
// if ( typeof ( expect ) === "undefined" ) { | ||
// ( globalThis as unknown as any ).expect = require( "chai" ) | ||
|
||
|
||
// } | ||
|
||
//sham mocha's it function to match jest's signature | ||
{ | ||
const mochaIt: ANY = it | ||
// // eslint-disable-next-line @typescript-eslint/ban-types | ||
// const shamIt = ( name: string, fn?: Function, timeout?: number ): void => { | ||
// // const doneCallback = () => { | ||
// // const isDone: IDoneCallback = ( args ) => { | ||
// // _test | ||
// // } | ||
|
||
|
||
// // } | ||
// const _test = mochaIt( name, () => { fn() } //fn as never ) | ||
// if ( timeout != null ) { | ||
// _test.timeout( timeout ) | ||
// } | ||
// } | ||
globalThis.it = ( name, fn, timeout ) => { | ||
const _test = mochaIt( name, fn ) | ||
if ( timeout != null ) { | ||
_test.timeout( timeout ) | ||
} | ||
} | ||
} | ||
|
||
//load up all test files following general advice from: https://stackoverflow.com/questions/32385219/mocha-tests-dont-run-with-webpack-and-mocha-loader | ||
{ | ||
const foundTestsRequire = ( require as unknown as NodeRequire ).context( "..", true, /.*\.test\.js?$/ ) | ||
//console.log( `keys found = ${ foundTestsRequire.keys().length }` ) | ||
for ( const key of foundTestsRequire.keys() ) { | ||
console.log( key ) | ||
foundTestsRequire( key ) | ||
} | ||
} | ||
|
||
//run tests | ||
mocha.run() | ||
|
This file was deleted.
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
Oops, something went wrong.