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: #9633

update

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

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

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 function Index() {
return (
<p> {JSON.stringify(nxCustomEnvVar())} </p>
);
};
export default Index;
`
);

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

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

expect(pageData).toContain('test value');

try {
await promisifiedTreeKill(p.pid, 'SIGKILL');
expect(await killPorts(port)).toBeTruthy();
} catch (err) {
expect(err).toBeFalsy();
}
}, 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 03ee6dd

Please sign in to comment.