Skip to content

Commit

Permalink
Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolo-ribaudo committed Oct 27, 2020
1 parent b59e188 commit a2decb5
Show file tree
Hide file tree
Showing 8 changed files with 832 additions and 107 deletions.
19 changes: 13 additions & 6 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,24 @@
"id-length": 0,
"new-cap": [2, {
"capIsNewExceptions": [
"ArrayFrom",
"Call",
"CreateIterResultObject",
"GetIntrinsic",
"GetIterator",
"OrdinaryObjectCreate",
"IsArray",
"IsCallable",
"IteratorClose",
"IteratorStep",
"SameValue",
"SameValueZero",
"ToString",
"Type"
],
]
}],
"no-magic-numbers": [2, {
"ignore": [0, 1]
"ignore": [0, 1, 2]
}],
"func-name-matching": 0
},
Expand All @@ -26,8 +33,8 @@
{
"files": "**/*.mjs",
"rules": {
"no-restricted-exports": 0,
},
},
],
"no-restricted-exports": 0
}
}
]
}
3 changes: 1 addition & 2 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
'use strict';

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

var implementation = require('./implementation');
var getPolyfill = require('./polyfill');
var shim = require('./shim');

var polyfill = callBind(getPolyfill(), String);
var polyfill = getPolyfill();

define(polyfill, {
getPolyfill: getPolyfill,
Expand Down
4 changes: 1 addition & 3 deletions index.mjs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import callBind from 'es-abstract/helpers/callBind.js';

import getPolyfill from 'es-map/polyfill';

export default callBind(getPolyfill(), String);
export default getPolyfill();

export { default as getPolyfill } from 'es-map/polyfill';
export { default as implementation } from 'es-map/implementation';
Expand Down
194 changes: 98 additions & 96 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,98 +1,100 @@
{
"name": "es-map",
"version": "0.0.0",
"description": "An ES-spec-compliant Map shim/polyfill/replacement that works as far down as ES3",
"main": "index.js",
"exports": {
".": [
{
"import": "./index.mjs",
"require": "./index.js",
"default": "./index.js"
},
"./index.js"
],
"./polyfill": [
{
"import": "./polyfill.mjs",
"require": "./polyfill.js",
"default": "./polyfill.js"
},
"./polyfill.js"
],
"./implementation": [
{
"import": "./implementation.mjs",
"require": "./implementation.js",
"default": "./implementation.js"
},
"./implementation.js"
],
"./shim": [
{
"import": "./shim.mjs",
"require": "./shim.js",
"default": "./shim.js"
},
"./shim.js"
],
"./auto": "./auto.js",
"./package.json": "./package.json"
},
"scripts": {
"prepublish": "safe-publish-latest",
"pretest": "npm run lint",
"lint": "eslint --ext=js,mjs .",
"tests-only": "tape 'test/**/*.js'",
"tests-esm": "node test/index.mjs",
"test": "npm run tests-only && npm run tests-esm",
"posttest": "aud --production",
"version": "auto-changelog && git add CHANGELOG.md",
"postversion": "auto-changelog && git add CHANGELOG.md && git commit --no-edit --amend && git tag -f \"v$(node -e \"console.log(require('./package.json').version)\")\""
},
"repository": {
"type": "git",
"url": "git+https://github.com/es-shims/es-map.git"
},
"keywords": [
"Set",
"Map",
"collections",
"shim",
"polyfill",
"es-shim",
"API"
],
"author": "Nicolò Ribaudo <nicolo.ribaudo@gmail.com>",
"funding": {
"url": "https://github.com/es-shims/es-map?sponsor=1"
},
"license": "MIT",
"bugs": {
"url": "https://github.com/es-shims/es-map/issues"
},
"homepage": "https://github.com/es-shims/es-map#readme",
"devDependencies": {
"@ljharb/eslint-config": "^17.2.0",
"aud": "^1.1.2",
"auto-changelog": "^2.2.1",
"eslint": "^7.12.0",
"functions-have-names": "^1.2.1",
"has-strict-mode": "^1.0.0",
"safe-publish-latest": "^1.1.4",
"tape": "^5.0.1"
},
"dependencies": {
"define-properties": "^1.1.3",
"es-abstract": "^1.18.0-next.1",
"has-symbols": "^1.0.1"
},
"auto-changelog": {
"output": "CHANGELOG.md",
"template": "keepachangelog",
"unreleased": false,
"commitLimit": false,
"backfillLimit": false,
"hideCredit": true
}
"name": "es-map",
"version": "0.0.0",
"description": "An ES-spec-compliant Map shim/polyfill/replacement that works as far down as ES3",
"main": "index.js",
"exports": {
".": [
{
"import": "./index.mjs",
"require": "./index.js",
"default": "./index.js"
},
"./index.js"
],
"./polyfill": [
{
"import": "./polyfill.mjs",
"require": "./polyfill.js",
"default": "./polyfill.js"
},
"./polyfill.js"
],
"./implementation": [
{
"import": "./implementation.mjs",
"require": "./implementation.js",
"default": "./implementation.js"
},
"./implementation.js"
],
"./shim": [
{
"import": "./shim.mjs",
"require": "./shim.js",
"default": "./shim.js"
},
"./shim.js"
],
"./auto": "./auto.js",
"./package.json": "./package.json"
},
"scripts": {
"prepublish": "safe-publish-latest",
"pretest": "npm run lint",
"lint": "eslint --ext=js,mjs .",
"tests-only": "tape 'test/**/*.js'",
"tests-esm": "node test/index.mjs",
"test": "npm run tests-only && npm run tests-esm",
"posttest": "aud --production",
"version": "auto-changelog && git add CHANGELOG.md",
"postversion": "auto-changelog && git add CHANGELOG.md && git commit --no-edit --amend && git tag -f \"v$(node -e \"console.log(require('./package.json').version)\")\""
},
"repository": {
"type": "git",
"url": "git+https://github.com/es-shims/es-map.git"
},
"keywords": [
"Set",
"Map",
"collections",
"shim",
"polyfill",
"es-shim",
"API"
],
"author": "Nicolò Ribaudo <nicolo.ribaudo@gmail.com>",
"funding": {
"url": "https://github.com/es-shims/es-map?sponsor=1"
},
"license": "MIT",
"bugs": {
"url": "https://github.com/es-shims/es-map/issues"
},
"homepage": "https://github.com/es-shims/es-map#readme",
"devDependencies": {
"@ljharb/eslint-config": "^17.2.0",
"array.from": "^1.1.0",
"aud": "^1.1.2",
"auto-changelog": "^2.2.1",
"eslint": "^7.12.0",
"functions-have-names": "^1.2.1",
"has-strict-mode": "^1.0.0",
"safe-publish-latest": "^1.1.4",
"tape": "^5.0.1"
},
"dependencies": {
"define-properties": "^1.1.3",
"es-abstract": "^1.18.0-next.1",
"globalthis": "^1.0.1",
"has-symbols": "^1.0.1"
},
"auto-changelog": {
"output": "CHANGELOG.md",
"template": "keepachangelog",
"unreleased": false,
"commitLimit": false,
"backfillLimit": false,
"hideCredit": true
}
}
11 changes: 11 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
'use strict';

var Map = require('../');
var test = require('tape');
var runTests = require('./tests');

test('as a function', function (t) {
runTests(Map, t);

t.end();
});
26 changes: 26 additions & 0 deletions test/index.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import Map, * as MapModule from 'es-map';
import test from 'tape';
import runTests from './tests.js';

test('as a function', (t) => {
console.log(Map);

runTests(Map, t);

t.end();
});

test('named exports', async (t) => {
t.deepEqual(
Object.keys(MapModule).sort(),
['default', 'shim', 'getPolyfill', 'implementation'].sort(),
'has expected named exports'
);

const { shim, getPolyfill, implementation } = MapModule;
t.equal(await import('es-map/shim'), shim, 'shim named export matches deep export');
t.equal(await import('es-map/implementation'), implementation, 'implementation named export matches deep export');
t.equal(await import('es-map/polyfill'), getPolyfill, 'getPolyfill named export matches deep export');

t.end();
});
43 changes: 43 additions & 0 deletions test/shimmed.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
'use strict';

require('../shim')();

var test = require('tape');

/*
* These delete are necessary because es-get-iterator (used by the array.from polyfill)
* only works when it's required _after_ shimming the Map.
*/
delete require.cache[process.cwd() + '/node_modules/is-map/index.js'];
delete require.cache[process.cwd() + '/node_modules/es-get-iterator/node_modules/es-abstract/helpers/callBound.js'];
delete require.cache[process.cwd() + '/node_modules/es-get-iterator/node_modules/es-abstract/GetIntrinsic.js'];
delete require.cache[process.cwd() + '/node_modules/es-get-iterator/index.js'];
delete require.cache[process.cwd() + '/node_modules/iterate-values/index.js'];
delete require.cache[process.cwd() + '/node_modules/array.from/implementation.js'];
delete require.cache[process.cwd() + '/node_modules/array.from/index.js'];
var ArrayFrom = require('array.from');

var runTests = require('./tests');

test('shimmed', function (t) {
runTests(Map, t);

// This test only works when the polyfill is applied globally
t.test('should have an iterator that works with polyfilled Array.from', { skip: true }, function (st) {
var map = new Map();

st.equal(map.set('a', 1), map, 'add "a"->1 to map');
st.equal(map.set('b', NaN), map, 'add "b"->NaN to map');
st.equal(map.set('c', false), map, 'add "c"->false to map');
st.deepEqual(ArrayFrom(map), [['a', 1], ['b', NaN], ['c', false]], 'Array.from(map) returns the entries');

// These don't work with es-get-iterator
st.deepEqual(ArrayFrom(map.keys()), ['a', 'b', 'c'], 'Array.from(map.keys()) returns the keys');
st.deepEqual(ArrayFrom(map.values()), [1, NaN, false], 'Array.from(map.values()) returns the values');
st.deepEqual(ArrayFrom(map.entries()), [['a', 1], ['b', NaN], ['c', false]], 'Array.from(map.entries()) returns the entries');

st.end();
});

t.end();
});
Loading

0 comments on commit a2decb5

Please sign in to comment.