Skip to content

Commit

Permalink
test: custom version from the mirror options
Browse files Browse the repository at this point in the history
  • Loading branch information
ddramone authored and Felix Rieseberg committed May 27, 2022
1 parent 56c6ee3 commit cd8eb66
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
7 changes: 5 additions & 2 deletions src/artifact-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,14 @@ function mirrorVar(
const snakeName = name.replace(/([a-z])([A-Z])/g, (_, a, b) => `${a}_${b}`).toLowerCase();

return (
// configs coming from .npmrc are always lowercase regardless how it was defined
// .npmrc
process.env[`npm_config_electron_${name.toLowerCase()}`] ||
process.env[`NPM_CONFIG_ELECTRON_${snakeName.toUpperCase()}`] ||
process.env[`npm_config_electron_${snakeName}`] ||
// package.json
process.env[`npm_package_config_electron_${name}`] ||
process.env[`npm_package_config_electron_${snakeName.toLowerCase()}`] ||
// env
process.env[`ELECTRON_${snakeName.toUpperCase()}`] ||
options[name] ||
defaultValue
Expand Down Expand Up @@ -71,6 +74,6 @@ export async function getArtifactRemoteURL(details: ElectronArtifactDetails): Pr
return `${base}${path}/${file}`;
}

export function getArtifactVersion(details: ElectronArtifactDetails) {
export function getArtifactVersion(details: ElectronArtifactDetails): string {
return normalizeVersion(mirrorVar('customVersion', details.mirrorOptions || {}, details.version));
}
1 change: 0 additions & 1 deletion test/checksums.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import * as crypto from 'crypto';
import * as fs from 'fs-extra';
import * as os from 'os';
import * as path from 'path';
Expand Down
16 changes: 16 additions & 0 deletions test/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,22 @@ describe('Public API', () => {
process.env.ELECTRON_CUSTOM_VERSION = '';
});

it('should download a custom version specified via mirror options', async () => {
const zipPath = await downloadArtifact({
artifactName: 'electron',
cacheRoot,
downloader,
platform: 'darwin',
arch: 'x64',
version: '2.0.3',
mirrorOptions: {
customVersion: '2.0.10',
},
});
expect(typeof zipPath).toEqual('string');
expect(path.basename(zipPath)).toMatchInlineSnapshot(`"electron-v2.0.10-darwin-x64.zip"`);
});

describe('sumchecker', () => {
beforeEach(() => {
jest.clearAllMocks();
Expand Down

0 comments on commit cd8eb66

Please sign in to comment.