-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add React Typescript E2E Tests (#240)
Create E2E helpers Change options passed to ForkTsChecker Webpack Plugin. Now async relies to env, use typescript incremental api to more faster type checking and avoid override compilerOptions
- Loading branch information
1 parent
57e16f8
commit 61bdc96
Showing
10 changed files
with
205 additions
and
154 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export const crossPlatformCommand = (cmd: string) => | ||
process.platform === 'win32' ? cmd + '.cmd' : cmd; |
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,45 @@ | ||
import { spawn, ChildProcessWithoutNullStreams } from 'child_process'; | ||
import * as path from 'path'; | ||
import { crossPlatformCommand } from './crossPlatformCommand'; | ||
import { waitForHttpStatus } from './waitForHttpStatus'; | ||
|
||
export async function run( | ||
cwd: string, | ||
args: string[], | ||
port?: number | ||
): Promise<{ | ||
errors: string[]; | ||
messages: string[]; | ||
process: ChildProcessWithoutNullStreams; | ||
}> { | ||
const process = spawn(crossPlatformCommand('yarn'), args, { | ||
cwd | ||
}); | ||
|
||
const stdoutMessages: string[] = []; | ||
const stderrMessages: string[] = []; | ||
|
||
process.stdout && | ||
process.stdout.on('data', data => { | ||
stdoutMessages.push(data.toString()); | ||
}); | ||
|
||
process.stderr && | ||
process.stderr.on('data', data => { | ||
stderrMessages.push(data.toString()); | ||
}); | ||
|
||
if (port) { | ||
await waitForHttpStatus({ | ||
port, | ||
host: 'localhost', | ||
canContinue: () => stderrMessages.length === 0 | ||
}); | ||
} | ||
|
||
return { | ||
process, | ||
errors: stderrMessages, | ||
messages: stdoutMessages | ||
}; | ||
} |
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,44 @@ | ||
import { request } from 'http'; | ||
|
||
export const waitForHttpStatus = ({ | ||
host, | ||
port, | ||
timeout = 100, | ||
ejectTimeout = 8000, | ||
method = 'GET', | ||
expectedStatusCode = 200, | ||
canContinue = () => true | ||
}: { | ||
host: string; | ||
port: number; | ||
timeout?: number; | ||
ejectTimeout?: number; | ||
method?: string; | ||
expectedStatusCode?: number; | ||
canContinue?: () => boolean; | ||
}) => | ||
new Promise((resolve, reject) => { | ||
const retry = () => setTimeout(main, timeout); | ||
|
||
let totalTimeout = 0; | ||
const main = () => { | ||
const req = request({ port, host }, response => { | ||
if (response.statusCode === expectedStatusCode) { | ||
return resolve(); | ||
} | ||
|
||
if (!canContinue() || totalTimeout > ejectTimeout) { | ||
return reject(); | ||
} | ||
|
||
totalTimeout += timeout; | ||
|
||
retry(); | ||
}); | ||
|
||
req.on('error', retry); | ||
req.end(); | ||
}; | ||
|
||
main(); | ||
}); |
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,32 @@ | ||
import getPort = require('get-port'); | ||
import { run } from '../../e2e-helpers/run'; | ||
import * as path from "path"; | ||
|
||
const workPath = path.join(require.resolve('../react-typescript/package.json'), '..'); | ||
|
||
describe('example:react-typescript', () => { | ||
beforeAll(() => jest.setTimeout(1000 * 60)); | ||
|
||
it('start', async () => { | ||
const port = await getPort(); | ||
|
||
const { | ||
errors, | ||
messages | ||
} = await run(workPath, ['start', '--smokeTest', `--port`, port.toString()], port); | ||
|
||
expect(errors.length).toBe(0); | ||
}); | ||
|
||
it('build', async () => { | ||
const { | ||
process, | ||
errors, | ||
messages | ||
} = await run(workPath, ['build']); | ||
|
||
process.on('exit', () => { | ||
expect(errors.length).toBe(0); | ||
}); | ||
}); | ||
}); |
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,32 @@ | ||
import getPort = require('get-port'); | ||
import { run } from '../../e2e-helpers/run'; | ||
import * as path from "path"; | ||
|
||
const workPath = path.join(require.resolve('../react/package.json'), '..'); | ||
|
||
describe('example:react', () => { | ||
beforeAll(() => jest.setTimeout(1000 * 60)); | ||
|
||
it('start', async () => { | ||
const port = await getPort(); | ||
|
||
const { | ||
errors, | ||
messages | ||
} = await run(workPath, ['start', '--smokeTest', `--port`, port.toString()], port); | ||
|
||
expect(errors.length).toBe(0); | ||
}); | ||
|
||
it('build', async () => { | ||
const { | ||
process, | ||
errors, | ||
messages | ||
} = await run(workPath, ['build']); | ||
|
||
process.on('exit', () => { | ||
expect(errors.length).toBe(0); | ||
}); | ||
}); | ||
}); |
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 was deleted.
Oops, something went wrong.
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.