-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(node): add e2e project generator (#14429)
- Loading branch information
Showing
27 changed files
with
451 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import { | ||
checkFilesDoNotExist, | ||
cleanupProject, | ||
killPort, | ||
newProject, | ||
promisifiedTreeKill, | ||
runCLI, | ||
runCommandUntil, | ||
uniq, | ||
} from '@nrwl/e2e/utils'; | ||
|
||
describe('Node Applications + webpack', () => { | ||
beforeEach(() => newProject()); | ||
|
||
afterEach(() => cleanupProject()); | ||
|
||
async function runE2eTests(appName: string) { | ||
process.env.PORT = '5000'; | ||
const childProcess = await runCommandUntil(`serve ${appName}`, (output) => { | ||
return output.includes('http://localhost:5000'); | ||
}); | ||
const result = runCLI(`e2e ${appName}-e2e`); | ||
expect(result).toContain('Setting up...'); | ||
expect(result).toContain('Tearing down..'); | ||
expect(result).toContain('Successfully ran target e2e'); | ||
|
||
await promisifiedTreeKill(childProcess.pid, 'SIGKILL'); | ||
await killPort(5000); | ||
process.env.PORT = ''; | ||
} | ||
|
||
it('should generate an app using webpack', async () => { | ||
const expressApp = uniq('expressapp'); | ||
const fastifyApp = uniq('fastifyapp'); | ||
const koaApp = uniq('koaapp'); | ||
|
||
runCLI( | ||
`generate @nrwl/node:app ${expressApp} --framework=express --no-interactive` | ||
); | ||
runCLI( | ||
`generate @nrwl/node:app ${fastifyApp} --framework=fastify --no-interactive` | ||
); | ||
runCLI( | ||
`generate @nrwl/node:app ${koaApp} --framework=koa --no-interactive` | ||
); | ||
|
||
// Use esbuild by default | ||
checkFilesDoNotExist(`apps/${expressApp}/webpack.config.js`); | ||
checkFilesDoNotExist(`apps/${fastifyApp}/webpack.config.js`); | ||
checkFilesDoNotExist(`apps/${koaApp}/webpack.config.js`); | ||
|
||
expect(() => runCLI(`lint ${expressApp}`)).not.toThrow(); | ||
expect(() => runCLI(`lint ${fastifyApp}`)).not.toThrow(); | ||
expect(() => runCLI(`lint ${koaApp}`)).not.toThrow(); | ||
expect(() => runCLI(`lint ${expressApp}-e2e`)).not.toThrow(); | ||
expect(() => runCLI(`lint ${fastifyApp}-e2e`)).not.toThrow(); | ||
expect(() => runCLI(`lint ${koaApp}-e2e`)).not.toThrow(); | ||
|
||
await runE2eTests(expressApp); | ||
await runE2eTests(fastifyApp); | ||
await runE2eTests(koaApp); | ||
}, 300_000); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 5 additions & 3 deletions
8
packages/node/src/generators/application/files/connect/src/main.ts__tmpl__
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,13 @@ | ||
import connect from 'connect'; | ||
|
||
const port = process.env.PORT ? Number(process.env.PORT) : <%= port %>; | ||
|
||
const app = connect(); | ||
|
||
app.use((req, res) => { | ||
res.end(JSON.stringify({ 'message': 'Hello API' })); | ||
}); | ||
|
||
app.listen(<%= port %>, () => { | ||
// Server is running | ||
}) | ||
app.listen(port, () => { | ||
console.log(`[ ready ] http://localhost:${port}`); | ||
}) |
10 changes: 6 additions & 4 deletions
10
packages/node/src/generators/application/files/express/src/main.ts__tmpl__
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,13 @@ | ||
import express from 'express'; | ||
const app = express(); | ||
|
||
const port = process.env.PORT ? Number(process.env.PORT) : <%= port %>; | ||
|
||
const app = express(); | ||
|
||
app.get('/', (req, res) => { | ||
res.send({ 'message': 'Hello API'}); | ||
}); | ||
|
||
app.listen(<%= port %>, () => { | ||
// Server is running | ||
}); | ||
app.listen(port, () => { | ||
console.log(`[ ready ] http://localhost:${port}`); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 5 additions & 3 deletions
8
packages/node/src/generators/application/files/koa/src/main.ts__tmpl__
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,13 @@ | ||
import koa from 'koa'; | ||
|
||
const port = process.env.PORT ? Number(process.env.PORT) : <%= port %>; | ||
|
||
const app = new koa(); | ||
|
||
app.use(async ctx =>{ | ||
ctx.body = { 'message': 'Hello API'}; | ||
}); | ||
|
||
app.listen(<%= port %>, () => { | ||
// Server is running | ||
}); | ||
app.listen(port, () => { | ||
console.log(`[ ready ] http://localhost:${port}`); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
013bb74
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
nx-dev – ./
nx-five.vercel.app
nx.dev
nx-dev-git-master-nrwl.vercel.app
nx-dev-nrwl.vercel.app