Skip to content

Commit 1d96bd1

Browse files
authored
Switch to pnpm (Closes #567) (#583)
Switch to pnpm. Fix bug with non-working dev server. Improve E2E tests, handle more cases. 1) If output stream is finished before success check to dev server, we should stop requests loop; 2) Read stderr stream along with stdout.
1 parent 5ad289c commit 1d96bd1

File tree

38 files changed

+14826
-13572
lines changed

38 files changed

+14826
-13572
lines changed

.cirrus.yml

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@ container:
22
image: nikolaik/python-nodejs:python3.5-nodejs14-alpine
33

44
test_task:
5-
install_script: yarn install
6-
build_script: yarn compile
7-
test_script: yarn test
5+
pnpm_cache:
6+
folder: /usr/local/lib/node_modules/pnpm
7+
install_pnpm_script:
8+
npm i -g pnpm
9+
node_modules_cache:
10+
folder: node_modules
11+
fingerprint_script: cat pnpm-lock.yaml
12+
populate_script: pnpm i
13+
build_script: pnpm compile
14+
test_script: pnpm test

e2e-helpers/multistream.d.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
declare module '@nearform/multistream' {
2+
import { Stream } from 'stream';
3+
4+
function multistream(streams: multistream.Streams): NodeJS.ReadableStream;
5+
6+
interface FactoryStreamCallback {
7+
(err: Error | null, stream: null): any;
8+
(err: null, stream: NodeJS.ReadableStream): any;
9+
}
10+
11+
namespace multistream {
12+
type LazyStream = () => Stream;
13+
type FactoryStream = (cb: FactoryStreamCallback) => void;
14+
type Streams = Array<LazyStream | NodeJS.ReadableStream> | FactoryStream;
15+
16+
function obj(streams: Streams): NodeJS.ReadableStream;
17+
}
18+
19+
interface MultiStream extends NodeJS.ReadableStream {
20+
new (streams: multistream.Streams);
21+
}
22+
23+
let ms: MultiStream;
24+
25+
export = ms;
26+
}

e2e-helpers/readProcessOutput.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import MultiStream from '@nearform/multistream';
2+
import { ChildProcessWithoutNullStreams } from 'child_process';
3+
4+
import { readStream } from './readStream';
5+
6+
export function readProcessOutput(process: ChildProcessWithoutNullStreams) {
7+
return readStream(new MultiStream([process.stderr, process.stdout]));
8+
}

e2e-helpers/readStream.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ export async function readStream(stream: NodeJS.ReadableStream) {
22
let output: string = '';
33

44
for await (const chunk of stream) {
5-
output += chunk;
5+
output += chunk.toString();
66
}
77

88
return output;

e2e-helpers/retryRequestWhile.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ type FuncParams = {
66
timeout?: number;
77
method?: string;
88
doWhile: (response: IncomingMessage) => boolean;
9+
forceResolveIf: () => boolean;
910
};
1011

1112
export function retryRequestWhile(
@@ -15,7 +16,8 @@ export function retryRequestWhile(
1516
interval = 350,
1617
timeout = 15000,
1718
method: requestMethod = 'GET',
18-
doWhile
19+
doWhile,
20+
forceResolveIf
1921
}: FuncParams
2022
): Promise<{ status?: number }> {
2123
return new Promise(resolve => {
@@ -46,6 +48,12 @@ export function retryRequestWhile(
4648
);
4749
}
4850

51+
if (forceResolveIf()) {
52+
return resolve({
53+
status: undefined
54+
});
55+
}
56+
4957
setTimeout(main.bind(null, retry), interval);
5058
};
5159

e2e-helpers/run.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { spawn } from 'child_process';
33
import { crossPlatformCommand } from './crossPlatformCommand';
44

55
export function run(cwd: string, args: string[]) {
6-
return spawn(crossPlatformCommand('yarn'), args, {
6+
return spawn(crossPlatformCommand('pnpm'), args, {
77
cwd
88
});
99
}

examples/__tests__/react-typescript.test.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import getPort = require('get-port');
22
import * as path from 'path';
33

4-
import { readStream } from '../../e2e-helpers/readStream';
4+
import { readProcessOutput } from '../../e2e-helpers/readProcessOutput';
55
import { retryRequestWhile } from '../../e2e-helpers/retryRequestWhile';
66
import { run } from '../../e2e-helpers/run';
77
import { terminateDevServer } from '../../e2e-helpers/terminateDevServer';
@@ -16,16 +16,22 @@ describe('example:react-typescript', () => {
1616

1717
const process = run(workPath, [
1818
'start',
19+
'--',
1920
'--port',
2021
devServerPort.toString(),
2122
'--smokeTest'
2223
]);
2324

25+
let outputStreamIsFinished = false;
26+
2427
const [output, httpRes] = await Promise.all([
25-
readStream(process.stdout),
28+
readProcessOutput(process).finally(() => {
29+
outputStreamIsFinished = true;
30+
}),
2631
retryRequestWhile('localhost', {
2732
port: devServerPort,
28-
doWhile: res => res.statusCode !== 200
33+
doWhile: res => res.statusCode !== 200,
34+
forceResolveIf: () => outputStreamIsFinished
2935
}).then(r => {
3036
terminateDevServer(devServerPort);
3137
return r;
@@ -39,7 +45,7 @@ describe('example:react-typescript', () => {
3945
it('build', async () => {
4046
const process = run(workPath, ['build']);
4147

42-
const output = await readStream(process.stdout);
48+
const output = await readProcessOutput(process);
4349

4450
expect(output).toContain(
4551
'Your application successfully built and available at'

examples/__tests__/react.test.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import getPort = require('get-port');
22
import * as path from 'path';
33

4-
import { readStream } from '../../e2e-helpers/readStream';
4+
import { readProcessOutput } from '../../e2e-helpers/readProcessOutput';
55
import { retryRequestWhile } from '../../e2e-helpers/retryRequestWhile';
66
import { run } from '../../e2e-helpers/run';
77
import { terminateDevServer } from '../../e2e-helpers/terminateDevServer';
@@ -16,16 +16,22 @@ describe('example:react', () => {
1616

1717
const process = run(workPath, [
1818
'start',
19+
'--',
1920
'--port',
2021
devServerPort.toString(),
2122
'--smokeTest'
2223
]);
2324

25+
let outputStreamIsFinished = false;
26+
2427
const [output, httpRes] = await Promise.all([
25-
readStream(process.stdout),
28+
readProcessOutput(process).finally(() => {
29+
outputStreamIsFinished = true;
30+
}),
2631
retryRequestWhile('localhost', {
2732
port: devServerPort,
28-
doWhile: res => res.statusCode !== 200
33+
doWhile: res => res.statusCode !== 200,
34+
forceResolveIf: () => outputStreamIsFinished
2935
}).then(r => {
3036
terminateDevServer(devServerPort);
3137
return r;
@@ -39,7 +45,7 @@ describe('example:react', () => {
3945
it('build', async () => {
4046
const process = run(workPath, ['build']);
4147

42-
const output = await readStream(process.stdout);
48+
const output = await readProcessOutput(process);
4349

4450
expect(output).toContain(
4551
'Your application successfully built and available at'

examples/react-typescript/package.json

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,19 @@
77
"build": "run build"
88
},
99
"dependencies": {
10-
"react": "16.13.0",
11-
"react-dom": "16.13.0"
10+
"react": "16.13.1",
11+
"react-dom": "16.13.1"
1212
},
1313
"devDependencies": {
14-
"@types/node": "13.9.1",
15-
"@types/react": "16.9.23",
16-
"@types/react-dom": "16.9.5",
17-
"fork-ts-checker-webpack-plugin": "4.1.0",
18-
"typescript": "3.8.3",
19-
"@zero-scripts/core": "^0.4.0",
20-
"@zero-scripts/plugin-webpack-spa": "^0.4.0",
21-
"@zero-scripts/plugin-webpack-react": "^0.4.0",
22-
"@zero-scripts/plugin-webpack-babel": "^0.4.0",
23-
"@zero-scripts/plugin-webpack-css": "^0.4.0"
14+
"@types/react": "16.9.35",
15+
"@types/react-dom": "16.9.8",
16+
"@zero-scripts/core": "workspace:*",
17+
"@zero-scripts/plugin-webpack-babel": "workspace:*",
18+
"@zero-scripts/plugin-webpack-css": "workspace:*",
19+
"@zero-scripts/plugin-webpack-react": "workspace:*",
20+
"@zero-scripts/plugin-webpack-spa": "workspace:*",
21+
"fork-ts-checker-webpack-plugin": "4.1.5",
22+
"typescript": "3.9.3"
2423
},
2524
"zero-scripts": {
2625
"workspace": [

examples/react/package.json

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,16 @@
77
"build": "run build"
88
},
99
"dependencies": {
10-
"react": "16.13.0",
11-
"react-dom": "16.13.0"
10+
"react": "16.13.1",
11+
"react-dom": "16.13.1"
1212
},
1313
"devDependencies": {
14-
"@zero-scripts/core": "^0.4.0",
15-
"@zero-scripts/plugin-webpack-spa": "^0.4.0",
16-
"@zero-scripts/plugin-webpack-react": "^0.4.0",
17-
"@zero-scripts/plugin-webpack-babel": "^0.4.0",
18-
"@zero-scripts/plugin-webpack-css": "^0.4.0"
14+
"@zero-scripts/core": "workspace:*",
15+
"@zero-scripts/plugin-webpack-babel": "workspace:*",
16+
"@zero-scripts/plugin-webpack-css": "workspace:*",
17+
"@zero-scripts/plugin-webpack-react": "workspace:*",
18+
"@zero-scripts/plugin-webpack-spa": "workspace:*",
19+
"@zero-scripts/plugin-webpack-eslint": "workspace:*"
1920
},
2021
"zero-scripts": {
2122
"workspace": [

0 commit comments

Comments
 (0)