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

Task: Move to Bun for tests #263

Merged
merged 2 commits into from
Jul 1, 2024
Merged
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
47 changes: 0 additions & 47 deletions .circleci/config.yml

This file was deleted.

2 changes: 1 addition & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"import/extensions": ["error", { "js": "never", "scss": "always", "ts": "never" }],
"import/no-unresolved": "off",
"import/prefer-default-export": "off",
"indent": ["error", "tab"],
"indent": ["error", "tab", { "SwitchCase": 1 }],
"lines-between-class-members": "off",
"no-case-declarations": "off",
"no-tabs": "off",
Expand Down
16 changes: 16 additions & 0 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: Pull Request

on:
pull_request:
branches: [develop]

jobs:
build-and-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: oven-sh/setup-bun@v1
- run: bun install
- run: bun eslint
- run: bun test
- run: bun run build
Binary file added bun.lockb
Binary file not shown.
2 changes: 2 additions & 0 deletions bunfig.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[test]
preload = ["./test/happydom.ts","./test/enzyme.ts"]
2 changes: 1 addition & 1 deletion dist/cjs/react-jsx-parser.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/cjs/react-jsx-parser.min.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/components/JsxParser.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { ComponentType, ExoticComponent } from 'react';
export declare type TProps = {
export type TProps = {
allowUnknownElements?: boolean;
autoCloseVoidElements?: boolean;
bindings?: {
Expand Down
2 changes: 1 addition & 1 deletion dist/es5/react-jsx-parser.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/es5/react-jsx-parser.min.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/helpers/parseStyle.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
declare type Style = string | Partial<CSSStyleDeclaration>;
type Style = string | Partial<CSSStyleDeclaration>;
/**
* Converts a CSS Style string
* @param {string | Partial<CSSStyleDeclaration>} style A string to convert, or object to return
Expand Down
2 changes: 1 addition & 1 deletion dist/umd/react-jsx-parser.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/umd/react-jsx-parser.min.js.map

Large diffs are not rendered by default.

37 changes: 0 additions & 37 deletions jest.config.js

This file was deleted.

1 change: 0 additions & 1 deletion jest/mock.files.ts

This file was deleted.

1 change: 0 additions & 1 deletion jest/mock.styles.ts

This file was deleted.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"@babel/preset-react": "^7.12.13",
"@babel/preset-typescript": "^7.12.13",
"@babel/runtime-corejs3": "^7.12.13",
"@happy-dom/global-registrator": "^14.12.3",
"@types/acorn": "^4.0.5",
"@types/enzyme": "^3.10.8",
"@types/jest": "^26.0.20",
Expand Down
File renamed without changes.
48 changes: 27 additions & 21 deletions source/components/JsxParser.test.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
// @ts-nocheck
/* eslint-disable function-paren-newline, no-console, no-underscore-dangle */
/* eslint-disable function-paren-newline, no-console, no-underscore-dangle, no-useless-escape */
import React from 'react'
import TestUtils from 'react-dom/test-utils'
import { mount, shallow } from 'enzyme' // eslint-disable-line import/no-extraneous-dependencies
import JsxParser from './JsxParser'

jest.unmock('acorn-jsx')
jest.unmock('./JsxParser')

const Custom = ({ children = [], className, text }) => (
<div className={className}>
{text}
Expand All @@ -18,24 +15,24 @@ const Custom = ({ children = [], className, text }) => (
describe('JsxParser Component', () => {
let parent = null
let originalConsoleError = null
let originalJsDomEmit = null
// let originalJsDomEmit = null

beforeAll(() => {
originalConsoleError = console.error
console.error = jest.fn()

originalJsDomEmit = window._virtualConsole.emit
window._virtualConsole.emit = jest.fn()
// originalJsDomEmit = window._virtualConsole.emit
// window._virtualConsole.emit = jest.fn()
})

afterAll(() => {
console.error = originalConsoleError
window._virtualConsole.emit = originalJsDomEmit
// window._virtualConsole.emit = originalJsDomEmit
})

beforeEach(() => {
console.error.mockReset()
window._virtualConsole.emit.mockReset()
// window._virtualConsole.emit.mockReset()
parent = document.createElement('div')
})

Expand Down Expand Up @@ -488,7 +485,9 @@ describe('JsxParser Component', () => {
message: expect.stringContaining('<bar> is unrecognized'),
}),
)
expect(wrapper.html()).toMatchSnapshot()
expect(wrapper.html()).toMatch(
'<div class=\"jsx-parser\"><div>Before </div><div> After</div></div>',
)
})
test('renders errors with renderError prop, if supplied', () => {
const onError = jest.fn()
Expand Down Expand Up @@ -882,7 +881,8 @@ describe('JsxParser Component', () => {

expect(window.foo).toHaveBeenCalledTimes(0)
expect(wrapper.find('span')).toHaveLength(0)
expect(wrapper.html()).toMatchSnapshot()
expect(wrapper.html())
.toMatch('<div class=\"jsx-parser\"><div>Before </div><div> After</div></div>')
})
test('can execute binary mathematical operations', () => {
const { rendered } = render(<JsxParser jsx="<span>{ 1 + 2 * 4 / 8 - 1 }</span>" />)
Expand Down Expand Up @@ -947,15 +947,17 @@ describe('JsxParser Component', () => {
expect(rendered.childNodes[0].textContent).toEqual('Nope')
expect(component.ParsedChildren[0].props.testProp).toEqual(true)
})
test('will render options', () => {
test.only('will render options', () => {
window.foo = jest.fn(() => true)
const wrapper = mount(
<JsxParser
jsx="<select><option>Some value</option></select>"
/>,
)

expect(wrapper.html()).toMatchSnapshot()
expect(wrapper.html()).toMatch(
'<div class=\"jsx-parser\"><select><option>Some value</option></select></div>',
)
})
describe('can evaluate multi-level property accessors', () => {
/* eslint-disable dot-notation,no-useless-concat */
Expand Down Expand Up @@ -1266,15 +1268,17 @@ describe('JsxParser Component', () => {
})

it('passes attributes', () => {
const PropTest = (props: { booleanAttribute: boolean}) => <>{`val:${props.booleanAttribute}`}</>
const PropTest = (props: { booleanAttribute: boolean }) => <>{`val:${props.booleanAttribute}`}</>
const { html, component } = render(
<JsxParser
renderInWrapper={false}
components={{ PropTest }}
bindings={{ items: [
{ name: 'Megeara', friend: true },
{ name: 'Austerious', friend: false },
] }}
bindings={{
items: [
{ name: 'Megeara', friend: true },
{ name: 'Austerious', friend: false },
],
}}
jsx="{items.map(item => <p><PropTest booleanAttribute={item.friend} /></p>)}"
/>,
)
Expand All @@ -1290,9 +1294,11 @@ describe('JsxParser Component', () => {
<JsxParser
renderInWrapper={false}
components={{ PropTest }}
bindings={{ items: [
{ name: 'Megeara', friend: true },
] }}
bindings={{
items: [
{ name: 'Megeara', friend: true },
],
}}
jsx="{items.map(item => <PropTest {...item} />)}"
/>,
)
Expand Down
Loading