Skip to content

Commit

Permalink
[dev] Update download.js tests to be "stateless" (#61525)
Browse files Browse the repository at this point in the history
* Make download.js test stateless so it can be parallelized

* Proper clean up etc

* Use CI prefixes for tmp dir creation + export it
  • Loading branch information
Joel Griffith authored Mar 26, 2020
1 parent b1fa159 commit 714743d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
2 changes: 2 additions & 0 deletions packages/kbn-test/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
30 changes: 21 additions & 9 deletions src/dev/build/tasks/nodejs/__tests__/download.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 714743d

Please sign in to comment.