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 codemod test #664

Merged
merged 1 commit into from
Jul 9, 2023
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
24 changes: 24 additions & 0 deletions codemod/rename-authuser-withauthusertokenssr.fixtures/inputB.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/* eslint-disable import/no-unresolved */
import React from 'react'
import {
AuthAction,
withAuthUser,
withAuthUserTokenSSR,
} from 'next-firebase-auth'

const Demo = () => <div>Some content</div>

export const getServerSideProps = withAuthUserTokenSSR({
whenUnauthed: AuthAction.REDIRECT_TO_LOGIN,
// eslint-disable-next-line no-unused-vars, no-useless-rename
})(async ({ AuthUser: user, req }) => {
// eslint-disable-next-line no-unused-vars
const { id } = user
return {
props: {
foo: 'bar',
},
}
})

export default withAuthUser()(Demo)
24 changes: 24 additions & 0 deletions codemod/rename-authuser-withauthusertokenssr.fixtures/outputB.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/* eslint-disable import/no-unresolved */
import React from 'react'
import {
AuthAction,
withAuthUser,
withAuthUserTokenSSR,
} from 'next-firebase-auth'

const Demo = () => <div>Some content</div>

export const getServerSideProps = withAuthUserTokenSSR({
whenUnauthed: AuthAction.REDIRECT_TO_LOGIN,
// eslint-disable-next-line no-unused-vars, no-useless-rename
})(async ({ user: user, req }) => {
// eslint-disable-next-line no-unused-vars
const { id } = user
return {
props: {
foo: 'bar',
},
}
})

export default withAuthUser()(Demo)
14 changes: 14 additions & 0 deletions codemod/rename-authuser-withauthusertokenssr.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,18 @@ describe('withAuthUserTokenSSR argument property change: AuthUser -> user', () =
const expected = read(`./${transformName}.fixtures/outputA.js`)
expect(actual).toEqual(expected)
})

it('works as expected with reassigned variable name', () => {
const actual = transform(
{
source: read(`./${transformName}.fixtures/inputB.js`),
path: require.resolve(`./${transformName}.fixtures/inputB.js`),
},
{ jscodeshift },
{}
)

const expected = read(`./${transformName}.fixtures/outputB.js`)
expect(actual).toEqual(expected)
})
})