Skip to content

Commit

Permalink
Fix #62 (Again) (#110)
Browse files Browse the repository at this point in the history
* Also Test on Pre-ES6 Node

* Use ES5-Compatible alternative of "fromEntries"

* Skip symbol-related tests on v10

* Use jest's skip instead
  • Loading branch information
Skn0tt committed Feb 3, 2021
1 parent e97fd00 commit ee2a21b
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 15 deletions.
21 changes: 10 additions & 11 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,22 @@ jobs:
build:
runs-on: ubuntu-latest

strategy:
matrix:
node: [14.x, 12.x, 10.x]

env:
CI: true
YARN_IGNORE_ENGINES: true

steps:
- name: Begin CI...
uses: actions/checkout@v2

- name: Use Node 12
- name: Use Node
uses: actions/setup-node@v1
with:
node-version: 12.x
node-version: ${{ matrix.node }}

- name: Use cached node_modules
uses: actions/cache@v2
Expand All @@ -23,28 +31,19 @@ jobs:
- name: Install dependencies
run: yarn install --frozen-lockfile
env:
CI: true

- name: Lint
run: yarn lint
env:
CI: true

- name: Test
run: yarn test --ci --coverage --maxWorkers=2
env:
CI: true

- name: Build
run: yarn build
env:
CI: true

- name: Run benchmark
run: node benchmark.js | tee output.txt
env:
CI: true
NODE_ENV: production

- name: Store benchmark result
Expand Down
14 changes: 13 additions & 1 deletion src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import { isArray, isMap, isPlainObject, isPrimitive, isSet } from './is';

import { ObjectID } from 'mongodb';

const isNode10 = process.version.indexOf('v10') === 0;

describe('stringify & parse', () => {
const cases: Record<
string,
Expand All @@ -16,6 +18,7 @@ describe('stringify & parse', () => {
output: JSONValue | ((v: JSONValue) => void);
outputAnnotations?: Annotations;
customExpectations?: (value: any) => void;
skipOnNode10?: boolean;
dontExpectEquality?: boolean;
}
> = {
Expand Down Expand Up @@ -424,6 +427,7 @@ describe('stringify & parse', () => {
},

'works for symbols': {
skipOnNode10: true,
input: () => {
const parent = Symbol('Parent');
const child = Symbol('Child');
Expand Down Expand Up @@ -473,6 +477,7 @@ describe('stringify & parse', () => {
},

'issue #58': {
skipOnNode10: true,
input: () => {
const cool = Symbol('cool');
SuperJSON.registerSymbol(cool);
Expand Down Expand Up @@ -580,10 +585,17 @@ describe('stringify & parse', () => {
output: expectedOutput,
outputAnnotations: expectedOutputAnnotations,
customExpectations,
skipOnNode10,
dontExpectEquality,
},
] of Object.entries(cases)) {
test(testName, () => {
let testFunc = test;

if (skipOnNode10 && isNode10) {
testFunc = test.skip;
}

testFunc(testName, () => {
const inputValue = typeof input === 'function' ? input() : input;

// let's make sure SuperJSON doesn't mutate our input!
Expand Down
7 changes: 4 additions & 3 deletions src/transformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -304,9 +304,10 @@ export const transformValue = (
return undefined;
};

const simpleRulesByAnnotation = Object.fromEntries(
simpleRules.map(r => [r.annotation, r])
);
const simpleRulesByAnnotation: Record<string, typeof simpleRules[0]> = {};
simpleRules.forEach(rule => {
simpleRulesByAnnotation[rule.annotation] = rule;
});

export const untransformValue = (json: any, type: TypeAnnotation) => {
if (isArray(type)) {
Expand Down

0 comments on commit ee2a21b

Please sign in to comment.