1
0
Fork 0
mirror of https://github.com/subosito/flutter-action.git synced 2024-08-16 10:19:50 +02:00
flutter/__tests__/release.test.ts

146 lines
4.8 KiB
TypeScript
Raw Normal View History

2020-10-08 03:22:02 +02:00
import fs = require('fs');
import path = require('path');
import nock = require('nock');
import * as release from '../src/release';
const platform = release.getPlatform();
describe('release tests', () => {
it('getPlatform', () => {
const platformMap: {[index: string]: string} = {
linux: 'linux',
2020-10-08 03:36:34 +02:00
darwin: 'macos',
win32: 'windows'
2020-10-08 03:22:02 +02:00
};
expect(platform).toEqual(platformMap[process.platform]);
});
describe('determineVersion', () => {
beforeEach(() => {
const dataDir = path.join(__dirname, 'data');
nock('https://storage.googleapis.com', {allowUnmocked: true})
2021-06-14 04:47:16 +02:00
.get(`/flutter_infra_release/releases/releases_${platform}.json`)
2020-10-08 03:22:02 +02:00
.replyWithFile(200, path.join(dataDir, `releases_${platform}.json`));
});
afterEach(() => {
nock.cleanAll();
nock.enableNetConnect();
});
it('channel: "stable", version: ""', async () => {
const result = await release.determineVersion('', 'stable', platform);
2021-04-26 16:24:40 +02:00
expect(result.version).toEqual('2.0.5');
expect(result.rawVersion).toEqual('2.0.5');
expect(result.downloadUrl).toContain('2.0.5');
2020-10-08 03:22:02 +02:00
});
it('channel: "beta", version: ""', async () => {
const result = await release.determineVersion('', 'beta', platform);
2021-04-26 16:24:40 +02:00
expect(result.version).toEqual('2.2.0-10.1.pre');
expect(result.rawVersion).toEqual('2.2.0-10.1.pre');
expect(result.downloadUrl).toContain('2.2.0-10.1.pre');
2020-10-08 03:22:02 +02:00
});
it('channel: "dev", version: ""', async () => {
const result = await release.determineVersion('', 'dev', platform);
2021-04-26 16:24:40 +02:00
expect(result.version).toEqual('2.2.0-10.1.pre');
expect(result.rawVersion).toEqual('2.2.0-10.1.pre');
expect(result.downloadUrl).toContain('2.2.0-10.1.pre');
2020-10-08 03:22:02 +02:00
});
it('channel: "dev", version: "1.17.x"', async () => {
const result = await release.determineVersion('1.17.x', 'dev', platform);
expect(result.version).toEqual('1.17.0-dev.5.0');
expect(result.rawVersion).toEqual('1.17.0-dev.5.0');
expect(result.downloadUrl).toContain('1.17.0-dev.5.0');
});
it('channel: "dev", version: "1.17"', async () => {
const result = await release.determineVersion('1.17', 'dev', platform);
expect(result.version).toEqual('1.17.0-dev.5.0');
expect(result.rawVersion).toEqual('1.17.0-dev.5.0');
expect(result.downloadUrl).toContain('1.17.0-dev.5.0');
});
it('channel: "dev", version: "1.7.x" (old format)', async () => {
const result = await release.determineVersion('1.7.x', 'dev', platform);
expect(result.version).toEqual('1.7.11');
expect(result.rawVersion).toEqual('v1.7.11');
expect(result.downloadUrl).toContain('v1.7.11');
});
it('channel: "dev", version: "1.7" (old format)', async () => {
const result = await release.determineVersion('1.7', 'dev', platform);
expect(result.version).toEqual('1.7.11');
expect(result.rawVersion).toEqual('v1.7.11');
expect(result.downloadUrl).toContain('v1.7.11');
});
it('channel: "dev", version: "0.12.x" (unknown)', async () => {
try {
await release.determineVersion('0.12.x', 'dev', platform);
} catch (e) {
expect(e.message).toEqual('unable to find release for 0.12.x');
}
});
it('channel: "dev", version: "0.12" (unknown)', async () => {
try {
await release.determineVersion('0.12', 'dev', platform);
} catch (e) {
expect(e.message).toEqual('unable to find release for 0.12');
}
});
it('channel: "dev", version: "1.17.0-dev.5.0"', async () => {
const result = await release.determineVersion(
'1.17.0-dev.5.0',
'dev',
platform
);
expect(result.version).toEqual('1.17.0-dev.5.0');
expect(result.rawVersion).toEqual('1.17.0-dev.5.0');
expect(result.downloadUrl).toContain('1.17.0-dev.5.0');
});
2020-11-23 14:11:57 +01:00
it('channel: "any", version: "1.17.x"', async () => {
const result = await release.determineVersion('1.17.x', 'any', platform);
expect(result.version).toEqual('1.17.5');
expect(result.rawVersion).toEqual('1.17.5');
expect(result.downloadUrl).toContain('1.17.5');
});
it('channel: "any", version: "1.19.x"', async () => {
const result = await release.determineVersion('1.19.x', 'any', platform);
expect(result.version).toEqual('1.19.0-5.0.pre');
expect(result.rawVersion).toEqual('1.19.0-5.0.pre');
expect(result.downloadUrl).toContain('1.19.0-5.0.pre');
});
it('channel: "any", version: "1.19.0-4.x"', async () => {
const result = await release.determineVersion(
'1.19.0-4.x',
'any',
platform
);
expect(result.version).toEqual('1.19.0-4.3.pre');
expect(result.rawVersion).toEqual('1.19.0-4.3.pre');
expect(result.downloadUrl).toContain('1.19.0-4.3.pre');
});
2020-10-08 03:22:02 +02:00
});
});