Skip to content

Commit

Permalink
Merge b760e1a into 0b51953
Browse files Browse the repository at this point in the history
  • Loading branch information
benmccann committed Apr 21, 2021
2 parents 0b51953 + b760e1a commit eb59458
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 4 deletions.
4 changes: 4 additions & 0 deletions .eslintrc.yml
@@ -1,5 +1,9 @@
extends:
- plugin:markdown/recommended
env:
es6: true
parserOptions:
sourceType: "module"
plugins:
- markdown
overrides:
Expand Down
19 changes: 19 additions & 0 deletions .test.sh
@@ -0,0 +1,19 @@
#!/bin/sh

# Runs the ESM compatibility tests only on Node 6 and higher

. ~/.nvm/nvm.sh

NODE_VERSION=$(nvm current)
echo "Using Node ${NODE_VERSION} in tests"

MAJOR_VERSION=`echo $NODE_VERSION | sed -E 's/v([0-9]+)\.[0-9]+\.[0-9]+/\1/'`
if [ "$MAJOR_VERSION" -ge "6" ]; then
echo "Node major version ${MAJOR_VERSION} supports ESM"
mocha --require esm --reporter spec --bail --check-leaks --ui qunit test/
else
echo "Node major version ${MAJOR_VERSION} does not support ESM"
# Even if you tell Mocha to exclude this test it will still import it and choke so we remove it
rm test/esm.js
mocha --reporter spec --bail --check-leaks --ui qunit test/
fi
2 changes: 1 addition & 1 deletion .travis.yml
Expand Up @@ -103,7 +103,7 @@ script:
- |
# Run test script, depending on nyc install
if npm_module_installed 'nyc'; then npm run-script test-ci
else npm test
else ./.test.sh
fi
- |
# Run linting, if eslint exists
Expand Down
File renamed without changes.
14 changes: 11 additions & 3 deletions package.json
Expand Up @@ -17,24 +17,32 @@
"benchmark": "2.1.4",
"eslint": "7.23.0",
"eslint-plugin-markdown": "2.0.1",
"esm": "3.2.25",
"mocha": "8.3.2",
"nyc": "15.1.0"
},
"files": [
"HISTORY.md",
"LICENSE",
"README.md",
"index.js"
"index.cjs",
"wrapper.mjs"
],
"engines": {
"node": ">= 0.6"
},
"scripts": {
"bench": "node benchmark/index.js",
"lint": "eslint .",
"test": "mocha --reporter spec --bail --check-leaks --ui qunit test/",
"test-ci": "nyc --reporter=text npm test",
"test": "mocha --require esm --reporter spec --bail --check-leaks --ui qunit test/",
"test-ci": "nyc --reporter=text ./.test.sh",
"test-cov": "nyc --reporter=html --reporter=text npm test",
"version": "node scripts/version-history.js && git add HISTORY.md"
},
"main": "./index.cjs",
"module": "./wrapper.mjs",
"exports": {
"import": "./wrapper.mjs",
"require": "./index.cjs"
}
}
17 changes: 17 additions & 0 deletions test/esm.js
@@ -0,0 +1,17 @@
import { deepEqual, equal } from 'assert';
import { parse, serialize } from '..';

const node_major_ver = process.versions.node.split('.')[0];

suite('esm');

test('parse', function() {
deepEqual({ foo: 'bar' }, parse('foo=bar'));
deepEqual({ foo: '123' }, parse('foo=123'));
});

test('serialize', function() {
equal('foo=bar', serialize('foo', 'bar'));
equal('foo=bar%20baz', serialize('foo', 'bar baz'));
equal('foo=', serialize('foo', ''));
});
3 changes: 3 additions & 0 deletions wrapper.mjs
@@ -0,0 +1,3 @@
import cjsModule from './index.cjs';
export const parse = cjsModule.parse;
export const serialize = cjsModule.serialize;

0 comments on commit eb59458

Please sign in to comment.