[src/dev/build] implement a getBuildNumber() mock (#74881)
Co-authored-by: spalger <spalger@users.noreply.github.com>
This commit is contained in:
parent
6ee2460ebc
commit
c8b63c0b1b
22
src/dev/build/lib/__mocks__/get_build_number.ts
Normal file
22
src/dev/build/lib/__mocks__/get_build_number.ts
Normal file
|
@ -0,0 +1,22 @@
|
|||
/*
|
||||
* Licensed to Elasticsearch B.V. under one or more contributor
|
||||
* license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright
|
||||
* ownership. Elasticsearch B.V. licenses this file to you under
|
||||
* the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
export function getBuildNumber() {
|
||||
return 12345;
|
||||
}
|
34
src/dev/build/lib/get_build_number.ts
Normal file
34
src/dev/build/lib/get_build_number.ts
Normal file
|
@ -0,0 +1,34 @@
|
|||
/*
|
||||
* Licensed to Elasticsearch B.V. under one or more contributor
|
||||
* license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright
|
||||
* ownership. Elasticsearch B.V. licenses this file to you under
|
||||
* the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
import os from 'os';
|
||||
import execa from 'execa';
|
||||
|
||||
export async function getBuildNumber() {
|
||||
if (/^win/.test(os.platform())) {
|
||||
// Windows does not have the wc process and `find /C /V ""` does not consistently work
|
||||
const log = await execa('git', ['log', '--format="%h"']);
|
||||
return log.stdout.split('\n').length;
|
||||
}
|
||||
|
||||
const wc = await execa.command('git log --format="%h" | wc -l', {
|
||||
shell: true,
|
||||
});
|
||||
return parseFloat(wc.stdout.trim());
|
||||
}
|
|
@ -20,6 +20,8 @@
|
|||
import pkg from '../../../../package.json';
|
||||
import { getVersionInfo } from './version_info';
|
||||
|
||||
jest.mock('./get_build_number');
|
||||
|
||||
describe('isRelease = true', () => {
|
||||
it('returns unchanged package.version, build sha, and build number', async () => {
|
||||
const versionInfo = await getVersionInfo({
|
||||
|
|
|
@ -17,22 +17,8 @@
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
import os from 'os';
|
||||
|
||||
import execa from 'execa';
|
||||
|
||||
async function getBuildNumber() {
|
||||
if (/^win/.test(os.platform())) {
|
||||
// Windows does not have the wc process and `find /C /V ""` does not consistently work
|
||||
const log = await execa('git', ['log', '--format="%h"']);
|
||||
return log.stdout.split('\n').length;
|
||||
}
|
||||
|
||||
const wc = await execa.command('git log --format="%h" | wc -l', {
|
||||
shell: true,
|
||||
});
|
||||
return parseFloat(wc.stdout.trim());
|
||||
}
|
||||
import { getBuildNumber } from './get_build_number';
|
||||
|
||||
interface Options {
|
||||
isRelease: boolean;
|
||||
|
|
|
@ -26,13 +26,10 @@ import {
|
|||
import { Config, Platform } from '../../lib';
|
||||
import { DownloadNodeBuilds } from './download_node_builds_task';
|
||||
|
||||
// import * as NodeShasumsNS from '../node_shasums';
|
||||
// import * as NodeDownloadInfoNS from '../node_download_info';
|
||||
// import * as DownloadNS from '../../../lib/download';
|
||||
// import { DownloadNodeBuilds } from '../download_node_builds_task';
|
||||
jest.mock('./node_shasums');
|
||||
jest.mock('./node_download_info');
|
||||
jest.mock('../../lib/download');
|
||||
jest.mock('../../lib/get_build_number');
|
||||
|
||||
expect.addSnapshotSerializer(createAnyInstanceSerializer(ToolingLog));
|
||||
|
||||
|
|
|
@ -27,6 +27,7 @@ import { Config } from '../../lib';
|
|||
import { ExtractNodeBuilds } from './extract_node_builds_task';
|
||||
|
||||
jest.mock('../../lib/fs');
|
||||
jest.mock('../../lib/get_build_number');
|
||||
|
||||
const Fs = jest.requireMock('../../lib/fs');
|
||||
|
||||
|
|
|
@ -29,6 +29,7 @@ import { VerifyExistingNodeBuilds } from './verify_existing_node_builds_task';
|
|||
jest.mock('./node_shasums');
|
||||
jest.mock('./node_download_info');
|
||||
jest.mock('../../lib/fs');
|
||||
jest.mock('../../lib/get_build_number');
|
||||
|
||||
const { getNodeShasums } = jest.requireMock('./node_shasums');
|
||||
const { getNodeDownloadInfo } = jest.requireMock('./node_download_info');
|
||||
|
|
Loading…
Reference in a new issue