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

Run @next/codemod tests in CI #70248

Merged
merged 7 commits into from
Sep 19, 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
1 change: 1 addition & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const customJestConfig = {
roots: [
'<rootDir>',
'<rootDir>/../packages/next/src/',
'<rootDir>/../packages/next-codemod/',
'<rootDir>/../packages/font/src/',
],
modulePathIgnorePatterns: ['/\\.next/'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ function Comp({children}) {

export default function Page() {
return (
<Link href="/" legacyBehavior>
(<Link href="/" legacyBehavior>
<Comp>Home</Comp>
</Link>
</Link>)
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ const a = <Comp />

export default function Page() {
return (
<Link href="/about" legacyBehavior>
(<Link href="/about" legacyBehavior>
{a}
</Link>
</Link>)
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import Link from 'next/link'

export default function Page() {
return (
<Link href="/about" className="some-class">
(<Link href="/about" className="some-class">
Link
</Link>
</Link>)
);
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import Link from 'next/link'
export default function Page() {
return (
<Link href="/about">
(<Link href="/about">
Link
</Link>
</Link>)
);
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import Link from 'next/link'
export default function Page() {
return (
<Link
(<Link
href="/about"
onClick={() => {
console.log('clicked')
}}
download>
Link
</Link>
</Link>)
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const CustomLink = ({
children,
}) => {
return (
<span className="link-container">
(<span className="link-container">
<Link href={href} legacyBehavior>
<a className="link" title={title}>
{children}
Expand All @@ -19,7 +19,7 @@ const CustomLink = ({
font-weight: 500;
}
`}</style>
</span>
</span>)
);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import img from "../public/img.jpg";
export default function Home() {
const myStyle = { color: 'black' };
return (
<div>
(<div>
<h1>Upgrade</h1>
<Image
src="/test.jpg"
Expand Down Expand Up @@ -101,6 +101,6 @@ export default function Home() {
width: "100%",
height: "auto"
}} />
</div>
</div>)
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ const Foo = require("foo");

export default function Home() {
return (
<div>
(<div>
<h1>Upgrade</h1>
<Image src="/test.jpg" width="200" height="300" />
<Named src="/test.png" width="400" height="500" />
<Foo />
</div>
</div>)
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export default withRouter(withAppContainer(withAuth(
const { router } = this.props

return (
<Page>
(<Page>
<Header
user={user}
pathname={router.pathname}
Expand All @@ -16,7 +16,7 @@ export default withRouter(withAppContainer(withAuth(
}}
onLogoRightClick={() => router.push('/logos')}
/>
</Page>
</Page>)
);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class AddonsPage extends React.Component {
router
} = this.props
return (
<Page>
(<Page>
<Header
user={user}
pathname={router.pathname}
Expand All @@ -19,7 +19,7 @@ class AddonsPage extends React.Component {
user={user}
url={router}
/>
</Page>
</Page>)
);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,21 @@ class Plan extends React.Component {
const { router} = this.props

return (
<Page>
(<Page>
<Header
user={user}
pathname={router.pathname}
onLogout={() => onUser(null)}
onLogoRightClick={() => Router.push('/logos')}
/>

<SubMenu
subscription={subscription}
teamsAndUser={teamsAndUser}
teams={teams}
user={user}
url={router}
/>
</Page>
</Page>)
);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export default withRouter(withAppContainer(withAuth(
const { props, state } = this

return (
<Header
(<Header
inverse={true}
user={props.user}
pathname={props.router.pathname}
Expand All @@ -15,7 +15,7 @@ export default withRouter(withAppContainer(withAuth(
props.router.push('/login')
}}
onLogoRightClick={() => props.router.push('/logos')}
/>
/>)
);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,26 @@ async function toObj(dir) {
return obj
}

it.each(readdirSync(fixtureDir))('should transform loader %s', async (loader) => {
const tmp = await mkdtemp(join(tmpdir(), `next-image-experimental-${loader}-`))
const originalCwd = process.cwd()
try {
await mkdir(tmp, opts)
await cp(join(fixtureDir, loader, 'input'), tmp, opts)
process.chdir(tmp)
const result = await Runner.run(transform, [`.`], {})
expect(result.error).toBe(0)
expect(
await toObj(tmp)
).toStrictEqual(
await toObj(join(fixtureDir, loader, 'output'))
)
} finally {
await rm(tmp, opts)
process.chdir(originalCwd)
}
})
// TODO: this is not working before it's built, re-enable on CI after migrating tests to defineTest
const loaders = readdirSync(fixtureDir)
for (const loader of loaders) {
it.skip(`should transform loader ${loader}`, async () => {
const tmp = await mkdtemp(join(tmpdir(), `next-image-experimental-${loader}-`))
const originalCwd = process.cwd()
try {
await mkdir(tmp, opts)
await cp(join(fixtureDir, loader, 'input'), tmp, opts)
process.chdir(tmp)
const result = await Runner.run(transform, [`.`], {})
expect(result.error).toBe(0)
expect(
await toObj(tmp)
).toStrictEqual(
await toObj(join(fixtureDir, loader, 'output'))
)
} finally {
await rm(tmp, opts)
process.chdir(originalCwd)
}
})
}
3 changes: 3 additions & 0 deletions packages/next-codemod/transforms/new-link.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// It might insert extra parnes for JSX components
// x-ref: https://github.com/facebook/jscodeshift/issues/534

import type { API, FileInfo } from 'jscodeshift'

export default function transformer(file: FileInfo, api: API) {
Expand Down
2 changes: 1 addition & 1 deletion run-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ const TIMINGS_API_HEADERS = {

const testFilters = {
development: new RegExp(
'^(test/(development|e2e)|packages/.*/src/.*)/.*\\.test\\.(js|jsx|ts|tsx)$'
'^(test/(development|e2e)|packages/.*/src/.*|packages/next-codemod/.*)/.*\\.test\\.(js|jsx|ts|tsx)$'
),
production: new RegExp(
'^(test/(production|e2e))/.*\\.test\\.(js|jsx|ts|tsx)$'
Expand Down
Loading