Skip to content

Commit

Permalink
fix(nextjs): update e2e test case to cover env variables exported fro…
Browse files Browse the repository at this point in the history
…m libraries

ISSUES CLOSED: nrwl#9633
  • Loading branch information
Nicholas Cunningham committed May 31, 2022
1 parent 6793e14 commit 246e0a8
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions e2e/next/src/next.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,50 @@ describe('Next.js Applications', () => {
});
}, 300000);

it('should display env values at runtime from a library', async () => {
const appName = uniq('app');
const libName = uniq('libName');

runCLI(`generate @nrwl/next:app ${appName} --no-interactive`);
runCLI(
`generate @nrwl/next:library ${libName} --no-component --no-interactive`
);

updateFile('.env.local', 'NX_CUSTOM_VAR=test value');
updateFile(
`libs/${libName}/src/index.ts`,
`
export const nxCustomEnvVar = () => {
return process.env['NX_CUSTOM_VAR'];
}
`
);

updateFile(
`apps/${appName}/pages/index.tsx`,
`
import React from 'react';
import { nxCustomEnvVar } from '@${proj}/${libName}';
export const Index = () => {
return (
<p> {JSON.stringify(nxCustomEnvVar())} </p>
);
};
export default Index;
`
);

// serve Next.js
await runCommandUntil(`run ${appName}:serve`, (output) => {
return output.indexOf(`[ ready ] on http://localhost:4200`) > -1;
});

const pageData = await getData(4200, '/');

expect(pageData).toContain('test value');
}, 300000);

it('should allow using a custom server implementation in TypeScript', async () => {
const appName = uniq('app');
const port = 4202;
Expand Down

0 comments on commit 246e0a8

Please sign in to comment.