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

babel-plugin-redwood-routes-auto-loader.tests.ts: Break up into separate tests #7858

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
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,6 @@ const FIXTURE_PATH = path.resolve(
'../../../../../../__fixtures__/example-todo-main/'
)

beforeAll(() => {
process.env.RWJS_CWD = FIXTURE_PATH
})
afterAll(() => {
delete process.env.RWJS_CWD
})

const transform = (filename: string) => {
const code = fs.readFileSync(filename, 'utf-8')
return babel.transform(code, {
Expand All @@ -27,14 +20,25 @@ const transform = (filename: string) => {
})
}

test('page auto loader correctly imports pages', () => {
const result = transform(getPaths().web.routes)
describe('page auto loader correctly imports pages', () => {
let result: babel.BabelFileResult | null

beforeAll(() => {
process.env.RWJS_CWD = FIXTURE_PATH
result = transform(getPaths().web.routes)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jtoar This was key. We left it outside beforeAll, so it tried to run getPaths() before RWJS_CWD was defined

})

// Pages are automatically imported
expect(result.code).toContain(`const HomePage = {
afterAll(() => {
delete process.env.RWJS_CWD
})

test('Pages are automatically imported', () => {
expect(result?.code).toContain(`const HomePage = {
name: "HomePage",
loader: () => import("`)
})

// Already imported pages are left alone.
expect(result.code).toContain(`import FooPage from 'src/pages/FooPage'`)
test('Already imported pages are left alone.', () => {
expect(result?.code).toContain(`import FooPage from 'src/pages/FooPage'`)
})
})