Headless tests - Include flipper logs in test output
Summary: Useful for debugging test failures. Reviewed By: bnelo12 Differential Revision: D16419182 fbshipit-source-id: 651eaded54aa001765aadcf966a2ce93e89f2854
This commit is contained in:
committed by
Facebook Github Bot
parent
7efe94a58f
commit
71784b1d64
@@ -48,7 +48,8 @@ const basicArgs = [
|
||||
params.insecurePort,
|
||||
];
|
||||
|
||||
const runHeadless = memoize((args: Array<string>) => {
|
||||
const runHeadless = memoize(
|
||||
(args: Array<string>): Promise<{output: Object, stderr: string}> => {
|
||||
return new Promise((resolve, reject) => {
|
||||
const stdoutChunks = [];
|
||||
const stderrChunks = [];
|
||||
@@ -63,13 +64,17 @@ const runHeadless = memoize((args: Array<string>) => {
|
||||
});
|
||||
process.stdout.on('end', chunk => {
|
||||
const stdout = stdoutChunks.join('');
|
||||
const stderr = stderrChunks.join('');
|
||||
try {
|
||||
resolve(JSON.parse(stdout));
|
||||
console.log(stderr);
|
||||
resolve({output: JSON.parse(stdout), stderr: stderr});
|
||||
} catch (e) {
|
||||
console.warn(stderrChunks.join(''));
|
||||
console.warn(stderr);
|
||||
reject(
|
||||
new Error(
|
||||
`Failed to parse headless output as JSON (${e.message}): ${stdout}`,
|
||||
`Failed to parse headless output as JSON (${
|
||||
e.message
|
||||
}): ${stdout}`,
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -79,11 +84,12 @@ const runHeadless = memoize((args: Array<string>) => {
|
||||
process.kill('SIGINT');
|
||||
}, 20000);
|
||||
});
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
function getPluginState(app: string, plugin: string): Promise<Object> {
|
||||
return runHeadless(basicArgs).then(result => {
|
||||
const pluginStates = result.store.pluginStates;
|
||||
const pluginStates = result.output.store.pluginStates;
|
||||
for (const pluginId of Object.keys(pluginStates)) {
|
||||
const matches = /([^#]+)#([^#]+)#([^#]+)#([^#]+)#([^#]+)/.exec(pluginId);
|
||||
if (
|
||||
@@ -104,7 +110,7 @@ test(
|
||||
'Flipper app appears in exported clients',
|
||||
() => {
|
||||
return runHeadless(basicArgs).then(result => {
|
||||
expect(result.clients.map(c => c.query.app)).toContain('Flipper');
|
||||
expect(result.output.clients.map(c => c.query.app)).toContain('Flipper');
|
||||
});
|
||||
},
|
||||
TEST_TIMEOUT_MS,
|
||||
@@ -114,7 +120,7 @@ test(
|
||||
'Output includes fileVersion',
|
||||
() => {
|
||||
return runHeadless(basicArgs).then(result => {
|
||||
expect(result.fileVersion).toMatch(/[0-9]+\.[0-9]+\.[0-9]+/);
|
||||
expect(result.output.fileVersion).toMatch(/[0-9]+\.[0-9]+\.[0-9]+/);
|
||||
});
|
||||
},
|
||||
TEST_TIMEOUT_MS,
|
||||
@@ -124,7 +130,7 @@ test(
|
||||
'Output includes device',
|
||||
() => {
|
||||
return runHeadless(basicArgs).then(result => {
|
||||
expect(result.device).toBeTruthy();
|
||||
expect(result.output.device).toBeTruthy();
|
||||
});
|
||||
},
|
||||
TEST_TIMEOUT_MS,
|
||||
@@ -134,7 +140,7 @@ test(
|
||||
'Output includes flipperReleaseRevision',
|
||||
() => {
|
||||
return runHeadless(basicArgs).then(result => {
|
||||
expect(result.flipperReleaseRevision).toBeTruthy();
|
||||
expect(result.output.flipperReleaseRevision).toBeTruthy();
|
||||
});
|
||||
},
|
||||
TEST_TIMEOUT_MS,
|
||||
@@ -144,7 +150,7 @@ test(
|
||||
'Output includes store',
|
||||
() => {
|
||||
return runHeadless(basicArgs).then(result => {
|
||||
expect(result.store).toBeTruthy();
|
||||
expect(result.output.store).toBeTruthy();
|
||||
});
|
||||
},
|
||||
TEST_TIMEOUT_MS,
|
||||
|
||||
Reference in New Issue
Block a user