@web/test-runner-mocha
Advanced tools
Comparing version
# @web/test-runner-mocha | ||
## 0.3.2 | ||
### Patch Changes | ||
- a137493: improve HTML tests setup | ||
## 0.3.1 | ||
@@ -4,0 +10,0 @@ |
@@ -5,4 +5,5 @@ /// <reference types="mocha" /> | ||
declare const mocha: BrowserMocha; | ||
export declare function runTests(testFn: () => unknown | Promise<unknown>): Promise<void>; | ||
export declare function sessionFinished(): void; | ||
export { mocha, sessionFailed }; | ||
//# sourceMappingURL=standalone.d.ts.map |
{ | ||
"name": "@web/test-runner-mocha", | ||
"version": "0.3.1", | ||
"version": "0.3.2", | ||
"publishConfig": { | ||
@@ -22,11 +22,7 @@ "access": "public" | ||
"build": "tsc", | ||
"build:production": "rimraf dist && rollup -c rollup.config.js" | ||
"build:production": "rimraf dist && rollup -c rollup.config.js", | ||
"test": "mocha test/**/*.test.js --reporter dot", | ||
"test:watch": "mocha test/**/*.test.js --watch --watch-files src,test --reporter dot" | ||
}, | ||
"files": [ | ||
"*.d.ts", | ||
"*.js", | ||
"*.mjs", | ||
"dist", | ||
"src" | ||
], | ||
"files": ["dist"], | ||
"keywords": [ | ||
@@ -33,0 +29,0 @@ "web", |
@@ -31,11 +31,6 @@ --- | ||
If you're writing tests as HTML, you can import this library to run tests with mocha. | ||
HTML files are loaded in the browser as is, and are not processed by a test framework. This way you have full control over the test environment. Depending on which test framework you're using, the way you run your tests can be a little different. | ||
### Inline tests | ||
With mocha, you need to define your tests inside the `runTests` function: | ||
You can write tests inline in the HTML page | ||
<details> | ||
<summary>View example</summary> | ||
```html | ||
@@ -45,9 +40,6 @@ <html> | ||
<script type="module"> | ||
import { mocha, sessionFinished, sessionFailed } from '@web/test-runner-mocha'; | ||
import { runTests } from '@web/test-runner-mocha'; | ||
try { | ||
// setup mocha | ||
mocha.setup({ ui: 'bdd' }); | ||
// write your actual tests | ||
runTests(async () => { | ||
// write your tests inline | ||
describe('HTML tests', () => { | ||
@@ -59,11 +51,5 @@ it('works', () => { | ||
// run the tests, and notify the test runner after finishing | ||
mocha.run(() => { | ||
sessionFinished(); | ||
}); | ||
} catch (error) { | ||
console.error(error); | ||
// notify the test runner about errors | ||
sessionFailed(error); | ||
} | ||
// or import your test file | ||
await import('./my-test.js'); | ||
}); | ||
</script> | ||
@@ -74,44 +60,2 @@ </body> | ||
</details> | ||
### Loading test files | ||
You can also use dynamic imports to load tests written in JS from the HTML page. | ||
<details> | ||
<summary>View example</summary> | ||
```html | ||
<html> | ||
<body> | ||
<script type="module"> | ||
import { mocha, sessionFinished } from '@web/test-runner-mocha'; | ||
async function run() { | ||
try { | ||
// setup mocha | ||
mocha.setup({ ui: 'bdd' }); | ||
// import your tests | ||
await import('./my-test.js'); | ||
// run the tests, and notify the test runner after finishing | ||
mocha.run(() => { | ||
sessionFinished(); | ||
}); | ||
} catch (error) { | ||
console.error(error); | ||
// notify the test runner about errors | ||
sessionFailed(error); | ||
} | ||
} | ||
run(); | ||
</script> | ||
</body> | ||
</html> | ||
``` | ||
</details> | ||
### Loading polyfills or libraries | ||
@@ -118,0 +62,0 @@ |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
3104151
-0.32%15
-25%2309
-15.54%140
-28.57%