Skip to content

Commit 36bb202

Browse files
dankogaiclaude
andcommitted
Make browser tests work from file:// URLs
Load tests as classic scripts against the UMD build instead of ES modules, which browsers block on file:// pages. Test files now take Combinatorics from a global (set by 00-node.js in Node, by index.html in the browser), like js-base64's test suite. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
1 parent c8036bf commit 36bb202

10 files changed

Lines changed: 39 additions & 26 deletions

test/00-node.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import * as _chai from 'chai';
2+
import * as _combinatorics from '../combinatorics.js';
23
global.chai = _chai;
34
// global.chai = require('chai');
5+
global.Combinatorics = _combinatorics;
46
global.isLegacySafari = false;

test/01-import.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import * as Combinatorics from '../combinatorics.js';
21
describe('import', () => {
32
for (const k in Combinatorics) {
43
const tn = k === 'version' ? 'string' : 'function';

test/02-arithmetics.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import {
2-
permutation, combination, factorial,factoradic
3-
} from '../combinatorics.js';
1+
var {
2+
permutation, combination, factorial, factoradic
3+
} = Combinatorics;
44

5-
const $$ = chai.expect.bind(chai);
5+
var $$ = chai.expect.bind(chai);
66

77
describe('permutation', () => {
88
it('permutation(3,2) === 6', ()=>$$(permutation(3, 2)).to.equal(6n));

test/03-basen.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { BaseN } from '../combinatorics.js';
1+
var { BaseN } = Combinatorics;
22

3-
const $$ = chai.expect.bind(chai);
3+
var $$ = chai.expect.bind(chai);
44

55
describe('class BaseN', () => {
66
let seed = '0123';

test/03-cartesianproduct.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { CartesianProduct } from '../combinatorics.js';
1+
var { CartesianProduct } = Combinatorics;
22

3-
const $$ = chai.expect.bind(chai);
3+
var $$ = chai.expect.bind(chai);
44

55
describe('class CartesianProduct', () => {
66
let seed = [];

test/03-combination.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { Combination } from '../combinatorics.js';
1+
var { Combination } = Combinatorics;
22

3-
const $$ = chai.expect.bind(chai);
3+
var $$ = chai.expect.bind(chai);
44

55
describe('class Combination', () => {
66
let seed = 'abcdefgh';

test/03-permcomb.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { Permutation, Combination } from '../combinatorics.js';
1+
var { Permutation, Combination } = Combinatorics;
22

3-
const $$ = chai.expect.bind(chai);
3+
var $$ = chai.expect.bind(chai);
44

55
class PermComb {
66
constructor(seed) {

test/03-permutation.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { Permutation } from '../combinatorics.js';
1+
var { Permutation } = Combinatorics;
22

3-
const $$ = chai.expect.bind(chai);
3+
var $$ = chai.expect.bind(chai);
44

55
describe('class Permutation', () => {
66
let seed = 'abcd';

test/03-powerset.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { PowerSet } from '../combinatorics.js';
1+
var { PowerSet } = Combinatorics;
22

3-
const $$ = chai.expect.bind(chai);
3+
var $$ = chai.expect.bind(chai);
44

55
describe('class PowerSet', () => {
66
let seed = [];

test/index.html

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,29 @@
2222
<script src="https://unpkg.com/chai@4.2.0/chai.js"></script>
2323
<script src="https://unpkg.com/mocha@8.0.1/mocha.js"></script>
2424
<script>mocha.setup('bdd')</script>
25-
<script type="module" src="./01-import.js"></script>
26-
<script type="module" src="./02-arithmetics.js"></script>
27-
<script type="module" src="./03-permutation.js"></script>
28-
<script type="module" src="./03-combination.js"></script>
29-
<script type="module" src="./03-basen.js"></script>
30-
<script type="module" src="./03-powerset.js"></script>
31-
<script type="module" src="./03-permcomb.js"></script>
32-
<script type="module">
25+
<script>
26+
/* minimal AMD shim so the UMD build registers as window.Combinatorics */
27+
define = (deps, factory) => {
28+
const exports = {};
29+
factory(null, exports);
30+
window.Combinatorics = exports;
31+
};
32+
define.amd = true;
33+
</script>
34+
<script src="../umd/combinatorics.js"></script>
35+
<script>delete window.define;</script>
36+
<script src="./01-import.js"></script>
37+
<script src="./02-arithmetics.js"></script>
38+
<script src="./03-permutation.js"></script>
39+
<script src="./03-combination.js"></script>
40+
<script src="./03-cartesianproduct.js"></script>
41+
<script src="./03-basen.js"></script>
42+
<script src="./03-powerset.js"></script>
43+
<script src="./03-permcomb.js"></script>
44+
<script defer>
3345
mocha.checkLeaks();
3446
mocha.run();
3547
</script>
3648
</body>
3749

38-
</html>
50+
</html>

0 commit comments

Comments
 (0)