[dev] Update download.js tests to be "stateless" (#61525)

* Make download.js test stateless so it can be parallelized

* Proper clean up etc

* Use CI prefixes for tmp dir creation + export it
This commit is contained in:
Joel Griffith 2020-03-26 15:13:33 -07:00 committed by GitHub
parent b1fa159e17
commit 714743d829
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 9 deletions

View file

@ -58,3 +58,5 @@ export {
export { runFailedTestsReporterCli } from './failed_tests_reporter';
export { makeJunitReportPath } from './junit_report_path';
export { CI_PARALLEL_PROCESS_PREFIX } from './ci_parallel_process_prefix';

View file

@ -18,27 +18,39 @@
*/
import { createServer } from 'http';
import { resolve } from 'path';
import { readFileSync } from 'fs';
import { join } from 'path';
import { tmpdir } from 'os';
import { mkdirp, readFileSync } from 'fs-extra';
import del from 'del';
import sinon from 'sinon';
import { CI_PARALLEL_PROCESS_PREFIX } from '@kbn/test';
import expect from '@kbn/expect';
import Wreck from '@hapi/wreck';
import { ToolingLog } from '@kbn/dev-utils';
import { download } from '../download';
const TMP_DESTINATION = resolve(__dirname, '__tmp__');
beforeEach(async () => {
await del(TMP_DESTINATION);
});
after(async () => {
await del(TMP_DESTINATION);
});
const getTempFolder = async () => {
const dir = join(tmpdir(), CI_PARALLEL_PROCESS_PREFIX, 'download-js-test-tmp-dir');
console.log(dir);
await mkdirp(dir);
return dir;
};
describe('src/dev/build/tasks/nodejs/download', () => {
const sandbox = sinon.createSandbox();
let TMP_DESTINATION;
let TMP_DIR;
beforeEach(async () => {
TMP_DIR = await getTempFolder();
TMP_DESTINATION = join(TMP_DIR, '__tmp_download_js_test_file__');
});
afterEach(async () => {
await del(TMP_DIR, { force: true });
});
afterEach(() => sandbox.reset());
const onLogLine = sandbox.stub();