Add test suite for headless

Summary:
Adds a JS test suite for running jest tests against flipper headless binaries. Replaces the jq-based bash script.

Simple sanity test included for all expected top level keys in output JSON.

Reviewed By: passy

Differential Revision: D15625723

fbshipit-source-id: 5ec8e764bcdbb99d9070de704e76a5cd9d8e5dc6
This commit is contained in:
John Knox
2019-06-07 08:19:58 -07:00
committed by Facebook Github Bot
parent 53748da75e
commit 4d6b39ae42
4 changed files with 4336 additions and 0 deletions

3
headless-tests/.babelrc Normal file
View File

@@ -0,0 +1,3 @@
{
"presets": ["@babel/preset-env", "@babel/preset-flow"]
}

View File

@@ -0,0 +1,115 @@
/**
* Copyright 2018-present Facebook.
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
* @format
*/
import {spawn} from 'child_process';
// $FlowFixMe
import memoize from 'lodash.memoize';
const TEST_TIMEOUT_MS = 30 * 1000;
const params = {
bin: process.env.FLIPPER_PATH || '/tmp/flipper-macos',
securePort: process.env.SECURE_PORT || '8088',
insecurePort: process.env.INSECURE_PORT || '8089',
device: process.env.DEVICE,
};
if (!params.device) {
console.warn(
'No device specified. Test may fail if more than one is present.',
);
}
const basicArgs = [
'-v',
...(params.device ? ['--device', params.device] : []),
'--secure-port',
params.securePort,
'--insecure-port',
params.insecurePort,
];
const runHeadless = memoize((args: Array<string>) => {
return new Promise((resolve, reject) => {
const stdoutChunks = [];
const stderrChunks = [];
console.info(`Running ${params.bin} ${args.join(' ')}`);
const process = spawn(params.bin, args, {});
process.stdout.setEncoding('utf8');
process.stdout.on('data', chunk => {
stdoutChunks.push(chunk);
});
process.stderr.on('data', chunk => {
stderrChunks.push(chunk);
});
process.stdout.on('end', chunk => {
const stdout = stdoutChunks.join('');
try {
resolve(JSON.parse(stdout));
} catch (e) {
console.warn(stderrChunks.join(''));
reject(
`Failed to parse headless output as JSON (${e.message}): ${stdout}`,
);
}
});
setTimeout(() => {
process.kill('SIGINT');
}, 10000);
});
});
test(
'Flipper app appears in exported clients',
() => {
return runHeadless(basicArgs).then(result => {
expect(result.clients.map(c => c.query.app)).toContain('Flipper');
});
},
TEST_TIMEOUT_MS,
);
test(
'Output includes fileVersion',
() => {
return runHeadless(basicArgs).then(result => {
expect(result.fileVersion).toMatch(/[0-9]+\.[0-9]+\.[0-9]+/);
});
},
TEST_TIMEOUT_MS,
);
test(
'Output includes device',
() => {
return runHeadless(basicArgs).then(result => {
expect(result.device).toBeTruthy();
});
},
TEST_TIMEOUT_MS,
);
test(
'Output includes flipperReleaseRevision',
() => {
return runHeadless(basicArgs).then(result => {
expect(result.flipperReleaseRevision).toBeTruthy();
});
},
TEST_TIMEOUT_MS,
);
test(
'Output includes store',
() => {
return runHeadless(basicArgs).then(result => {
expect(result.store).toBeTruthy();
});
},
TEST_TIMEOUT_MS,
);

View File

@@ -0,0 +1,24 @@
{
"name": "headless-tests",
"version": "1.0.0",
"main": "index.js",
"scripts": {
"test": "jest",
"test:debug": "node --inspect node_modules/.bin/jest --runInBand"
},
"jest": {
"transform": {
"^.+\\.jsx?$": "babel-jest"
}
},
"devDependencies": {
"jest": "^24.7.1"
},
"license": "MIT",
"dependencies": {
"@babel/preset-env": "^7.4.5",
"@babel/preset-flow": "^7.0.0",
"babel-jest": "^24.8.0",
"lodash.memoize": "^4.1.2"
}
}

4194
headless-tests/yarn.lock Normal file

File diff suppressed because it is too large Load Diff