Skip to content

Commit b82b543

Browse files
committed
[src/dev/build] implement a getBuildNumber() mock
1 parent be7e21c commit b82b543

File tree

7 files changed

+62
-19
lines changed

7 files changed

+62
-19
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
* Licensed to Elasticsearch B.V. under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch B.V. licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
export function getBuildNumber() {
21+
return 12345;
22+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Licensed to Elasticsearch B.V. under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch B.V. licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
import os from 'os';
21+
import execa from 'execa';
22+
23+
export async function getBuildNumber() {
24+
if (/^win/.test(os.platform())) {
25+
// Windows does not have the wc process and `find /C /V ""` does not consistently work
26+
const log = await execa('git', ['log', '--format="%h"']);
27+
return log.stdout.split('\n').length;
28+
}
29+
30+
const wc = await execa.command('git log --format="%h" | wc -l', {
31+
shell: true,
32+
});
33+
return parseFloat(wc.stdout.trim());
34+
}

src/dev/build/lib/version_info.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
import pkg from '../../../../package.json';
2121
import { getVersionInfo } from './version_info';
2222

23+
jest.mock('./get_build_number');
24+
2325
describe('isRelease = true', () => {
2426
it('returns unchanged package.version, build sha, and build number', async () => {
2527
const versionInfo = await getVersionInfo({

src/dev/build/lib/version_info.ts

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,8 @@
1717
* under the License.
1818
*/
1919

20-
import os from 'os';
21-
2220
import execa from 'execa';
23-
24-
async function getBuildNumber() {
25-
if (/^win/.test(os.platform())) {
26-
// Windows does not have the wc process and `find /C /V ""` does not consistently work
27-
const log = await execa('git', ['log', '--format="%h"']);
28-
return log.stdout.split('\n').length;
29-
}
30-
31-
const wc = await execa.command('git log --format="%h" | wc -l', {
32-
shell: true,
33-
});
34-
return parseFloat(wc.stdout.trim());
35-
}
21+
import { getBuildNumber } from './get_build_number';
3622

3723
interface Options {
3824
isRelease: boolean;

src/dev/build/tasks/nodejs/download_node_builds_task.test.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,10 @@ import {
2626
import { Config, Platform } from '../../lib';
2727
import { DownloadNodeBuilds } from './download_node_builds_task';
2828

29-
// import * as NodeShasumsNS from '../node_shasums';
30-
// import * as NodeDownloadInfoNS from '../node_download_info';
31-
// import * as DownloadNS from '../../../lib/download';
32-
// import { DownloadNodeBuilds } from '../download_node_builds_task';
3329
jest.mock('./node_shasums');
3430
jest.mock('./node_download_info');
3531
jest.mock('../../lib/download');
32+
jest.mock('../../lib/get_build_number');
3633

3734
expect.addSnapshotSerializer(createAnyInstanceSerializer(ToolingLog));
3835

src/dev/build/tasks/nodejs/extract_node_builds_task.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import { Config } from '../../lib';
2727
import { ExtractNodeBuilds } from './extract_node_builds_task';
2828

2929
jest.mock('../../lib/fs');
30+
jest.mock('../../lib/get_build_number');
3031

3132
const Fs = jest.requireMock('../../lib/fs');
3233

src/dev/build/tasks/nodejs/verify_existing_node_builds_task.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import { VerifyExistingNodeBuilds } from './verify_existing_node_builds_task';
2929
jest.mock('./node_shasums');
3030
jest.mock('./node_download_info');
3131
jest.mock('../../lib/fs');
32+
jest.mock('../../lib/get_build_number');
3233

3334
const { getNodeShasums } = jest.requireMock('./node_shasums');
3435
const { getNodeDownloadInfo } = jest.requireMock('./node_download_info');

0 commit comments

Comments
 (0)