Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
4 changes: 2 additions & 2 deletions docs/docs/dev-server/plugins/import-maps.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ When the plugin is installed any import maps found in HTML files are used to res
<script type="importmap">
{
"imports": {
"chai": "/node_modules/@esm-bundle/chai/chai.js",
"chai": "/node_modules/chai/index.js",
"./app.js": "./mocked-app.js"
}
}
Expand All @@ -74,7 +74,7 @@ When the plugin is installed any import maps found in HTML files are used to res

<body>
<script type="module">
// mapped to /node_modules/@esm-bundle/chai/chai.js
// mapped to /node_modules/chai/index.js
import chai from 'chai';
// mapped to ./mocked-app.js
import app from './app.js';
Expand Down
4 changes: 2 additions & 2 deletions docs/docs/test-runner/writing-tests/helper-libraries.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ Not all helper libraries ship es modules which are usable in the browser. On thi

## Assertions

[chai](https://www.npmjs.com/package/chai) is a popular assertion library. It doesn't ship an es module, but you can use [@esm-bundle/chai](https://www.npmjs.com/package/@esm-bundle/chai) for that.
[chai](https://www.npmjs.com/package/chai) is a popular assertion library.

```js
import { expect } from '@esm-bundle/chai';
import { expect } from 'chai';

expect(undefined).to.not.be.a('function');
```
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/test-runner/writing-tests/html-tests.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ With mocha, you need to define your tests inside the `runTests` function:
<body>
<script type="module">
import { runTests } from '@web/test-runner-mocha';
import { expect } from '@esm-bundle/chai';
import { expect } from 'chai';

runTests(async () => {
// write your tests inline
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/test-runner/writing-tests/js-tests.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Javascript files are loaded by the test framework that is configured. The defaul
For example:

```js
import { expect } from '@esm-bundle/chai';
import { expect } from 'chai';
import { myFunction } from '../src/myFunction.js';

describe('myFunction', () => {
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/test-runner/writing-tests/mocking.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ Test file:
<body>
<script type="module">
import { runTests } from '@web/test-runner-mocha';
import { expect } from '@esm-bundle/chai';
import { expect } from 'chai';
// import inside will resolve to ./mocks/postData.js
import { sendMessage } from '../src/sendMessage.js';
// resolves to ./mocks/postData.js
Expand Down
29 changes: 13 additions & 16 deletions docs/guides/going-buildless/es-modules.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,30 +158,28 @@ UMD modules are "universal modules", meaning they support multiple module format

You can actually import these libraries using a module import, but instead of exporting something, the UMD module will register itself to the window. You can set up a proxy file to reexport this variable from the window.

A good example of this is the chai library:

`test/chai.js`:
`test/some-umd-lib.js`:

```js
// import the chai UMD file
import 'chai/chai.js';
// import the UMD file
import 'some-umd-lib/dist/some-umd-lib.js';

// get a reference to chai on the window
const chai = window.chai;
const { expect, assert } = chai;
// get a reference to the library on the window
const someUmdLib = window.someUmdLib;
const { foo, bar } = someUmdLib;

// reexport chai
export default chai;
// reexport names exports from chai
export { expect, assert };
// reexport the library
export default someUmdLib;
// reexport named exports from the library
export { foo, bar };
```

`test/my-element.test.js`:

```js
import { expect } from './chai.js';
import { foo } from './some-umd-lib.js';

expect('foo').to.equal('bar');
foo('bar');
```

This approach has the downside of polluting the global scope. And you can only use a single version of this library since different versions would overwrite each other. This makes it unsuitable for shared code, but this is a good option for applications and tests.
Expand All @@ -191,8 +189,7 @@ This approach has the downside of polluting the global scope. And you can only u
JSPM is a CDN which ships es module variants of the NPM registry, using a clever build system to transform CommonJS into es modules. You could import from your CDN directly in your code. This will always require an internet connection and is unsuitable for published code. But it is an interesting option.

```js
import chai from 'https://jspm.dev/chai';
const { expect } = chai;
import { expect } from 'https://jspm.dev/chai';

expect('foo').to.equal('bar');
```
Expand Down
2 changes: 1 addition & 1 deletion docs/guides/test-runner/code-coverage/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ As good citizens we start with the tests first
👉 `test/calc.test.js`

```js
import { expect } from '@esm-bundle/chai';
import { expect } from 'chai';
import { calc } from '../src/calc.js';

it('does plus for 2 numbers', () => {
Expand Down
4 changes: 2 additions & 2 deletions docs/guides/test-runner/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Now that we know what we want we need to place this file somewhere and run a too
1. Install the necessary packages

```
npm i --save-dev @web/test-runner @esm-bundle/chai
npm i --save-dev @web/test-runner chai
```

2. Add a script to your `package.json`
Expand Down Expand Up @@ -56,7 +56,7 @@ fair enough - we didn't create a test file yet.
1. Take the spec/test from above and create a test file `test/sum.test.js`.

```js
import { expect } from '@esm-bundle/chai';
import { expect } from 'chai';
import { sum } from '../src/sum.js';

it('sums up 2 numbers', () => {
Expand Down
4 changes: 2 additions & 2 deletions docs/guides/test-runner/responsive.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ npm i --save-dev @web/test-runner-commands
With that we get a `setViewport` method which we can put to good use.

```js
import { expect } from '@esm-bundle/chai';
import { expect } from 'chai';
import { setViewport } from '@web/test-runner-commands';
import { isMobile } from '../src/isMobile';

Expand Down Expand Up @@ -110,7 +110,7 @@ Next, we can write our tests to change the viewport and check if our media queri

<script type="module">
import { runTests } from '@web/test-runner-mocha';
import { expect } from '@esm-bundle/chai';
import { expect } from 'chai';
import { setViewport } from '@web/test-runner-commands';

runTests(() => {
Expand Down
2 changes: 1 addition & 1 deletion docs/guides/test-runner/watch-and-debug/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ We want to be able to pass in a string like `1 + 2 + 3` to get its sum.
👉 `test/calc.test.js`

```js
import { expect } from '@esm-bundle/chai';
import { expect } from 'chai';
import { calc } from '../src/calc.js';

it('calculates sums', () => {
Expand Down
2 changes: 1 addition & 1 deletion integration/test-runner/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@
"@web/test-runner-core": "^1.0.0"
},
"devDependencies": {
"@esm-bundle/chai": "^4.1.5"
"chai": "^6.0.0"
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<html>
<body>
<script type="module">
import { expect } from '../../../../../node_modules/@esm-bundle/chai/esm/chai.js';
import { expect } from '../../../../../node_modules/chai/index.js';
import { runTests } from '../../../../../packages/test-runner-mocha/dist/standalone.js';

runTests(() => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { expect } from '../../../../../node_modules/@esm-bundle/chai/esm/chai.js';
import { expect } from '../../../../../node_modules/chai/index.js';

describe('basic test', () => {
it('works', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { expect } from '../../../../../node_modules/@esm-bundle/chai/esm/chai.js';
import { expect } from '../../../../../node_modules/chai/index.js';

it('supports object spread', () => {
const foo = { a: 1 };
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { expect } from '../../../../../node_modules/@esm-bundle/chai/esm/chai.js';
import { expect } from '../../../../../node_modules/chai/index.js';
import module from './module-features-a.js';

it('supports static imports', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { expect } from '../../../../../node_modules/@esm-bundle/chai/esm/chai.js';
import { expect } from '../../../../../node_modules/chai/index.js';

describe('timers test', () => {
it('can call setTimeout', async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { expect } from '../../../../../node_modules/@esm-bundle/chai/esm/chai.js';
import { expect } from '../../../../../node_modules/chai/index.js';

describe('basic test', () => {
it('works', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { expect } from '../../../../../node_modules/@esm-bundle/chai/esm/chai.js';
import { expect } from '../../../../../node_modules/chai/index.js';

describe('basic test', () => {
it('works', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { expect } from '../../../../../node_modules/@esm-bundle/chai/esm/chai.js';
import { expect } from '../../../../../node_modules/chai/index.js';

it('can run a test with focus a', async () => {
const input = document.createElement('input');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { expect } from '../../../../../node_modules/@esm-bundle/chai/esm/chai.js';
import { expect } from '../../../../../node_modules/chai/index.js';

it('can run a test with focus b', async () => {
const input = document.createElement('input');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { expect } from '../../../../../node_modules/@esm-bundle/chai/esm/chai.js';
import { expect } from '../../../../../node_modules/chai/index.js';

it('can run a test with focus c', async () => {
const input = document.createElement('input');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { expect } from '../../../../../node_modules/@esm-bundle/chai/esm/chai.js';
import { expect } from '../../../../../node_modules/chai/index.js';

it('can run a test with focus d', async () => {
const input = document.createElement('input');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { expect } from '../../../../../node_modules/@esm-bundle/chai/esm/chai.js';
import { expect } from '../../../../../node_modules/chai/index.js';

it('can run a test with focus e', async () => {
const input = document.createElement('input');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { expect } from '../../../../../node_modules/@esm-bundle/chai/esm/chai.js';
import { expect } from '../../../../../node_modules/chai/index.js';

afterEach(() => {
throw new Error('error thrown in afterEach hook');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { expect } from '../../../../../node_modules/@esm-bundle/chai/esm/chai.js';
import { expect } from '../../../../../node_modules/chai/index.js';

after(() => {
throw new Error('error thrown in after hook');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { expect } from '../../../../../node_modules/@esm-bundle/chai/esm/chai.js';
import { expect } from '../../../../../node_modules/chai/index.js';

beforeEach(() => {
throw new Error('error thrown in beforeEach hook');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { expect } from '../../../../../node_modules/@esm-bundle/chai/esm/chai.js';
import { expect } from '../../../../../node_modules/chai/index.js';

before(() => {
throw new Error('error thrown in before hook');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { expect } from '../../../../../node_modules/@esm-bundle/chai/esm/chai.js';
import { expect } from '../../../../../node_modules/chai/index.js';

it('bad predicate', function () {
const fixture = { x: 'x' };
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { expect } from '../../../../../node_modules/@esm-bundle/chai/esm/chai.js';
import { expect } from '../../../../../node_modules/chai/index.js';

throw new Error('This is thrown before running tests');

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { expect } from '../../../../../node_modules/@esm-bundle/chai/esm/chai.js';
import { expect } from '../../../../../node_modules/chai/index.js';
import './shared-a.js';

it('object diff A', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { expect } from '../../../../../node_modules/@esm-bundle/chai/esm/chai.js';
import { expect } from '../../../../../node_modules/chai/index.js';

it('readonly actual', function () {
const fixture = Object.freeze({ x: {} });
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { expect } from '../../../../../node_modules/@esm-bundle/chai/esm/chai.js';
import { expect } from '../../../../../node_modules/chai/index.js';

it('string diff', () => {
expect('foo').to.equal('bar');
Expand Down
Loading