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

feat(typescript): convert to typescript #51

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
3 changes: 2 additions & 1 deletion .babelrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"presets": [
"amex"
"amex",
"@babel/preset-typescript"
]
}
3 changes: 2 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"extends": "amex"
"extends": "amex",
"ignorePatterns": ["dist/**/*"]
}
2 changes: 2 additions & 0 deletions .github/workflows/health-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ jobs:
run: npm ci
env:
NODE_ENV: development
- name: Build
run: npm run build
- name: Run Test Script
run: npm test
env:
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ jobs:
node-version-file: ".nvmrc"
- name: Install dependencies
run: npm ci
- name: Build
run: npm run build
xAndreiLi marked this conversation as resolved.
Show resolved Hide resolved
- name: Release
env:
GIT_AUTHOR_EMAIL: ${{ secrets.GIT_AUTHOR_EMAIL }}
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ jobs:
run: npm ci
env:
NODE_ENV: development
- name: Build
run: npm run build
- name: Unit Tests
run: npm run test:unit
env:
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules
test-results
.jest-cache
.jest-cache
dist
31 changes: 0 additions & 31 deletions __tests__/__snapshots__/index.spec.jsx.snap

This file was deleted.

31 changes: 31 additions & 0 deletions __tests__/__snapshots__/index.spec.tsx.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`createSharedReactContext should not return the same context object if the key does not matches 1`] = `
<TestComponent>
<div
id="value"
>
default
</div>
</TestComponent>
`;

exports[`createSharedReactContext should return the same context object if the key matches 1`] = `
<TestComponent>
<div
id="value"
>
context value
</div>
</TestComponent>
`;

exports[`createSharedReactContext should use the same default value from first call 1`] = `
<TestComponent>
<div
id="value"
>
default
</div>
</TestComponent>
`;
29 changes: 10 additions & 19 deletions __tests__/index.spec.jsx → __tests__/index.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,20 @@

import React from 'react';
import { mount } from 'enzyme';
import createSharedReactContext from '../src/index';

describe('createSharedContext', () => {
describe('createSharedReactContext', () => {
it('should create context with React.createContext', () => {
const createContextSpy = jest.spyOn(React, 'createContext');
// eslint-disable-next-line unicorn/import-index, global-require
const createSharedContext = require('../index.js');
createSharedContext('myCoolDefaultValue', 'sharedContext');
createSharedReactContext('myCoolDefaultValue', 'sharedContext');

expect(createContextSpy).toHaveBeenCalledWith('myCoolDefaultValue');
});

it('should return the same context object if the key matches', () => {
// eslint-disable-next-line unicorn/import-index, global-require
const createSharedContext = require('../index.js');
const testProvider = createSharedContext('', 'sharedContext');
const testProvider = createSharedReactContext('', 'sharedContext');
const { Provider } = testProvider;
const testConsumer = createSharedContext('', 'sharedContext');
const testConsumer = createSharedReactContext('', 'sharedContext');
const { Consumer } = testConsumer;
const mockValue = 'context value';

Expand All @@ -53,12 +50,10 @@ describe('createSharedContext', () => {
});

it('should not return the same context object if the key does not matches', () => {
// eslint-disable-next-line unicorn/import-index, global-require
const createSharedContext = require('../index.js');
const defaultValue = 'default';
const testProvider = createSharedContext('', 'sharedContext');
const testProvider = createSharedReactContext('', 'sharedContext');
const { Provider } = testProvider;
const testConsumer = createSharedContext(defaultValue, 'someContext');
const testConsumer = createSharedReactContext(defaultValue, 'someContext');
const { Consumer } = testConsumer;
const mockValue = 'context value';

Expand All @@ -80,11 +75,9 @@ describe('createSharedContext', () => {
});

it('should use the same default value from first call', () => {
// eslint-disable-next-line unicorn/import-index, global-require
const createSharedContext = require('../index.js');
const defaultValue = 'default';
createSharedContext(defaultValue, 'someContext');
const testDefaultContext = createSharedContext('never see this', 'someContext');
createSharedReactContext(defaultValue, 'someContext');
const testDefaultContext = createSharedReactContext('never see this', 'someContext');
const { Consumer } = testDefaultContext;

const TestComponent = () => (
Expand All @@ -105,10 +98,8 @@ describe('createSharedContext', () => {
it('should warn and return context with React.createContext', () => {
const createContextSpy = jest.spyOn(React, 'createContext');
const warnSpy = jest.spyOn(console, 'warn');
// eslint-disable-next-line unicorn/import-index, global-require
const createSharedContext = require('../index.js');

createSharedContext('default');
createSharedReactContext('default', undefined);
expect(warnSpy).toHaveBeenCalledWith('Second parameter in createSharedReactContext was not set, defaulting to React.createContext');
expect(createContextSpy).toHaveBeenCalledWith('default');
});
Expand Down
Loading
Loading