Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #62 (Again) #110

Merged
merged 5 commits into from
Feb 3, 2021
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
> = {
'works for objects': {
Expand Down Expand Up @@ -426,6 +429,7 @@ describe('stringify & parse', () => {
},

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

'issue #58': {
skipOnNode10: true,
input: () => {
const cool = Symbol('cool');
SuperJSON.registerSymbol(cool);
Expand Down Expand Up @@ -561,9 +566,16 @@ describe('stringify & parse', () => {
output: expectedOutput,
outputAnnotations: expectedOutputAnnotations,
customExpectations,
skipOnNode10,
},
] 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 @@ -294,9 +294,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