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

Add (failing) tests for edge cases discovered in facebook/react #10

Merged
merged 1 commit into from
Apr 30, 2023
Merged
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
69 changes: 69 additions & 0 deletions transforms/__tests__/codemod-missing-await-act.js
Original file line number Diff line number Diff line change
Expand Up @@ -375,3 +375,72 @@ test("react-dom API", () => {
})"
`);
});

test("intentional interleaving is stopped", () => {
expect(
applyTransform(`
import { act } from '@testing-library/react'
test('test', () => {
Promise.all([act(), act()])
})
`)
).toMatchInlineSnapshot(`
"import { act } from '@testing-library/react'
test('test', async () => {
Promise.all([await act(), await act()])
})"
`);
});

// Found in facebook/react
test.failing("already async act", () => {
// Code should be unchanged ideally.
const code = dedent`
import { act } from '@testing-library/react'
test('test', async () => {
await expect(act(someAsyncScopeFromExternal)).rejects.toThrow()
})
`;

expect(applyTransform(code)).toEqual(code);
});

test("only calls are codemodded", () => {
expect(
applyTransform(`
import { act } from '@testing-library/react'
test('test', async() => {
act()
// don't await this assignment
const myAct = act
})
`)
).toMatchInlineSnapshot(`
"import { act } from '@testing-library/react'
test('test', async() => {
await act()
// don't await this assignment
const myAct = act
})"
`);
});

test.failing("reassignment is not tracked", () => {
expect(
applyTransform(`
import { act } from '@testing-library/react'

const myAct = act
test('test', () => {
myAct()
})
`)
).toEqual(dedent`
import { act } from '@testing-library/react'

const myAct = act
test('test', async () => {
await myAct()
})
`);
});