Skip to content

Commit a2decb5

Browse files
Tests
1 parent b59e188 commit a2decb5

File tree

8 files changed

+832
-107
lines changed

8 files changed

+832
-107
lines changed

.eslintrc

+13-6
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,24 @@
77
"id-length": 0,
88
"new-cap": [2, {
99
"capIsNewExceptions": [
10+
"ArrayFrom",
11+
"Call",
1012
"CreateIterResultObject",
1113
"GetIntrinsic",
14+
"GetIterator",
1215
"OrdinaryObjectCreate",
16+
"IsArray",
17+
"IsCallable",
18+
"IteratorClose",
19+
"IteratorStep",
1320
"SameValue",
1421
"SameValueZero",
1522
"ToString",
1623
"Type"
17-
],
24+
]
1825
}],
1926
"no-magic-numbers": [2, {
20-
"ignore": [0, 1]
27+
"ignore": [0, 1, 2]
2128
}],
2229
"func-name-matching": 0
2330
},
@@ -26,8 +33,8 @@
2633
{
2734
"files": "**/*.mjs",
2835
"rules": {
29-
"no-restricted-exports": 0,
30-
},
31-
},
32-
],
36+
"no-restricted-exports": 0
37+
}
38+
}
39+
]
3340
}

index.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
'use strict';
22

33
var define = require('define-properties');
4-
var callBind = require('es-abstract/helpers/callBind');
54

65
var implementation = require('./implementation');
76
var getPolyfill = require('./polyfill');
87
var shim = require('./shim');
98

10-
var polyfill = callBind(getPolyfill(), String);
9+
var polyfill = getPolyfill();
1110

1211
define(polyfill, {
1312
getPolyfill: getPolyfill,

index.mjs

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
import callBind from 'es-abstract/helpers/callBind.js';
2-
31
import getPolyfill from 'es-map/polyfill';
42

5-
export default callBind(getPolyfill(), String);
3+
export default getPolyfill();
64

75
export { default as getPolyfill } from 'es-map/polyfill';
86
export { default as implementation } from 'es-map/implementation';

package.json

+98-96
Original file line numberDiff line numberDiff line change
@@ -1,98 +1,100 @@
11
{
2-
"name": "es-map",
3-
"version": "0.0.0",
4-
"description": "An ES-spec-compliant Map shim/polyfill/replacement that works as far down as ES3",
5-
"main": "index.js",
6-
"exports": {
7-
".": [
8-
{
9-
"import": "./index.mjs",
10-
"require": "./index.js",
11-
"default": "./index.js"
12-
},
13-
"./index.js"
14-
],
15-
"./polyfill": [
16-
{
17-
"import": "./polyfill.mjs",
18-
"require": "./polyfill.js",
19-
"default": "./polyfill.js"
20-
},
21-
"./polyfill.js"
22-
],
23-
"./implementation": [
24-
{
25-
"import": "./implementation.mjs",
26-
"require": "./implementation.js",
27-
"default": "./implementation.js"
28-
},
29-
"./implementation.js"
30-
],
31-
"./shim": [
32-
{
33-
"import": "./shim.mjs",
34-
"require": "./shim.js",
35-
"default": "./shim.js"
36-
},
37-
"./shim.js"
38-
],
39-
"./auto": "./auto.js",
40-
"./package.json": "./package.json"
41-
},
42-
"scripts": {
43-
"prepublish": "safe-publish-latest",
44-
"pretest": "npm run lint",
45-
"lint": "eslint --ext=js,mjs .",
46-
"tests-only": "tape 'test/**/*.js'",
47-
"tests-esm": "node test/index.mjs",
48-
"test": "npm run tests-only && npm run tests-esm",
49-
"posttest": "aud --production",
50-
"version": "auto-changelog && git add CHANGELOG.md",
51-
"postversion": "auto-changelog && git add CHANGELOG.md && git commit --no-edit --amend && git tag -f \"v$(node -e \"console.log(require('./package.json').version)\")\""
52-
},
53-
"repository": {
54-
"type": "git",
55-
"url": "git+https://github.com/es-shims/es-map.git"
56-
},
57-
"keywords": [
58-
"Set",
59-
"Map",
60-
"collections",
61-
"shim",
62-
"polyfill",
63-
"es-shim",
64-
"API"
65-
],
66-
"author": "Nicolò Ribaudo <nicolo.ribaudo@gmail.com>",
67-
"funding": {
68-
"url": "https://github.com/es-shims/es-map?sponsor=1"
69-
},
70-
"license": "MIT",
71-
"bugs": {
72-
"url": "https://github.com/es-shims/es-map/issues"
73-
},
74-
"homepage": "https://github.com/es-shims/es-map#readme",
75-
"devDependencies": {
76-
"@ljharb/eslint-config": "^17.2.0",
77-
"aud": "^1.1.2",
78-
"auto-changelog": "^2.2.1",
79-
"eslint": "^7.12.0",
80-
"functions-have-names": "^1.2.1",
81-
"has-strict-mode": "^1.0.0",
82-
"safe-publish-latest": "^1.1.4",
83-
"tape": "^5.0.1"
84-
},
85-
"dependencies": {
86-
"define-properties": "^1.1.3",
87-
"es-abstract": "^1.18.0-next.1",
88-
"has-symbols": "^1.0.1"
89-
},
90-
"auto-changelog": {
91-
"output": "CHANGELOG.md",
92-
"template": "keepachangelog",
93-
"unreleased": false,
94-
"commitLimit": false,
95-
"backfillLimit": false,
96-
"hideCredit": true
97-
}
2+
"name": "es-map",
3+
"version": "0.0.0",
4+
"description": "An ES-spec-compliant Map shim/polyfill/replacement that works as far down as ES3",
5+
"main": "index.js",
6+
"exports": {
7+
".": [
8+
{
9+
"import": "./index.mjs",
10+
"require": "./index.js",
11+
"default": "./index.js"
12+
},
13+
"./index.js"
14+
],
15+
"./polyfill": [
16+
{
17+
"import": "./polyfill.mjs",
18+
"require": "./polyfill.js",
19+
"default": "./polyfill.js"
20+
},
21+
"./polyfill.js"
22+
],
23+
"./implementation": [
24+
{
25+
"import": "./implementation.mjs",
26+
"require": "./implementation.js",
27+
"default": "./implementation.js"
28+
},
29+
"./implementation.js"
30+
],
31+
"./shim": [
32+
{
33+
"import": "./shim.mjs",
34+
"require": "./shim.js",
35+
"default": "./shim.js"
36+
},
37+
"./shim.js"
38+
],
39+
"./auto": "./auto.js",
40+
"./package.json": "./package.json"
41+
},
42+
"scripts": {
43+
"prepublish": "safe-publish-latest",
44+
"pretest": "npm run lint",
45+
"lint": "eslint --ext=js,mjs .",
46+
"tests-only": "tape 'test/**/*.js'",
47+
"tests-esm": "node test/index.mjs",
48+
"test": "npm run tests-only && npm run tests-esm",
49+
"posttest": "aud --production",
50+
"version": "auto-changelog && git add CHANGELOG.md",
51+
"postversion": "auto-changelog && git add CHANGELOG.md && git commit --no-edit --amend && git tag -f \"v$(node -e \"console.log(require('./package.json').version)\")\""
52+
},
53+
"repository": {
54+
"type": "git",
55+
"url": "git+https://github.com/es-shims/es-map.git"
56+
},
57+
"keywords": [
58+
"Set",
59+
"Map",
60+
"collections",
61+
"shim",
62+
"polyfill",
63+
"es-shim",
64+
"API"
65+
],
66+
"author": "Nicolò Ribaudo <nicolo.ribaudo@gmail.com>",
67+
"funding": {
68+
"url": "https://github.com/es-shims/es-map?sponsor=1"
69+
},
70+
"license": "MIT",
71+
"bugs": {
72+
"url": "https://github.com/es-shims/es-map/issues"
73+
},
74+
"homepage": "https://github.com/es-shims/es-map#readme",
75+
"devDependencies": {
76+
"@ljharb/eslint-config": "^17.2.0",
77+
"array.from": "^1.1.0",
78+
"aud": "^1.1.2",
79+
"auto-changelog": "^2.2.1",
80+
"eslint": "^7.12.0",
81+
"functions-have-names": "^1.2.1",
82+
"has-strict-mode": "^1.0.0",
83+
"safe-publish-latest": "^1.1.4",
84+
"tape": "^5.0.1"
85+
},
86+
"dependencies": {
87+
"define-properties": "^1.1.3",
88+
"es-abstract": "^1.18.0-next.1",
89+
"globalthis": "^1.0.1",
90+
"has-symbols": "^1.0.1"
91+
},
92+
"auto-changelog": {
93+
"output": "CHANGELOG.md",
94+
"template": "keepachangelog",
95+
"unreleased": false,
96+
"commitLimit": false,
97+
"backfillLimit": false,
98+
"hideCredit": true
99+
}
98100
}

test/index.js

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
'use strict';
2+
3+
var Map = require('../');
4+
var test = require('tape');
5+
var runTests = require('./tests');
6+
7+
test('as a function', function (t) {
8+
runTests(Map, t);
9+
10+
t.end();
11+
});

test/index.mjs

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import Map, * as MapModule from 'es-map';
2+
import test from 'tape';
3+
import runTests from './tests.js';
4+
5+
test('as a function', (t) => {
6+
console.log(Map);
7+
8+
runTests(Map, t);
9+
10+
t.end();
11+
});
12+
13+
test('named exports', async (t) => {
14+
t.deepEqual(
15+
Object.keys(MapModule).sort(),
16+
['default', 'shim', 'getPolyfill', 'implementation'].sort(),
17+
'has expected named exports'
18+
);
19+
20+
const { shim, getPolyfill, implementation } = MapModule;
21+
t.equal(await import('es-map/shim'), shim, 'shim named export matches deep export');
22+
t.equal(await import('es-map/implementation'), implementation, 'implementation named export matches deep export');
23+
t.equal(await import('es-map/polyfill'), getPolyfill, 'getPolyfill named export matches deep export');
24+
25+
t.end();
26+
});

test/shimmed.js

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
'use strict';
2+
3+
require('../shim')();
4+
5+
var test = require('tape');
6+
7+
/*
8+
* These delete are necessary because es-get-iterator (used by the array.from polyfill)
9+
* only works when it's required _after_ shimming the Map.
10+
*/
11+
delete require.cache[process.cwd() + '/node_modules/is-map/index.js'];
12+
delete require.cache[process.cwd() + '/node_modules/es-get-iterator/node_modules/es-abstract/helpers/callBound.js'];
13+
delete require.cache[process.cwd() + '/node_modules/es-get-iterator/node_modules/es-abstract/GetIntrinsic.js'];
14+
delete require.cache[process.cwd() + '/node_modules/es-get-iterator/index.js'];
15+
delete require.cache[process.cwd() + '/node_modules/iterate-values/index.js'];
16+
delete require.cache[process.cwd() + '/node_modules/array.from/implementation.js'];
17+
delete require.cache[process.cwd() + '/node_modules/array.from/index.js'];
18+
var ArrayFrom = require('array.from');
19+
20+
var runTests = require('./tests');
21+
22+
test('shimmed', function (t) {
23+
runTests(Map, t);
24+
25+
// This test only works when the polyfill is applied globally
26+
t.test('should have an iterator that works with polyfilled Array.from', { skip: true }, function (st) {
27+
var map = new Map();
28+
29+
st.equal(map.set('a', 1), map, 'add "a"->1 to map');
30+
st.equal(map.set('b', NaN), map, 'add "b"->NaN to map');
31+
st.equal(map.set('c', false), map, 'add "c"->false to map');
32+
st.deepEqual(ArrayFrom(map), [['a', 1], ['b', NaN], ['c', false]], 'Array.from(map) returns the entries');
33+
34+
// These don't work with es-get-iterator
35+
st.deepEqual(ArrayFrom(map.keys()), ['a', 'b', 'c'], 'Array.from(map.keys()) returns the keys');
36+
st.deepEqual(ArrayFrom(map.values()), [1, NaN, false], 'Array.from(map.values()) returns the values');
37+
st.deepEqual(ArrayFrom(map.entries()), [['a', 1], ['b', NaN], ['c', false]], 'Array.from(map.entries()) returns the entries');
38+
39+
st.end();
40+
});
41+
42+
t.end();
43+
});

0 commit comments

Comments
 (0)