2019-08-13 12:11:30 +02:00
|
|
|
import io = require('@actions/io');
|
|
|
|
import fs = require('fs');
|
|
|
|
import path = require('path');
|
2019-08-16 13:31:13 +02:00
|
|
|
import nock = require('nock');
|
2019-08-13 12:11:30 +02:00
|
|
|
|
|
|
|
const toolDir = path.join(__dirname, 'runner', 'tools');
|
2019-08-13 12:23:34 +02:00
|
|
|
const tempDir = path.join(__dirname, 'runner', 'temp');
|
2019-08-16 13:31:13 +02:00
|
|
|
const dataDir = path.join(__dirname, 'data');
|
2019-08-13 12:11:30 +02:00
|
|
|
|
|
|
|
process.env['RUNNER_TOOL_CACHE'] = toolDir;
|
2019-08-13 12:23:34 +02:00
|
|
|
process.env['RUNNER_TEMP'] = tempDir;
|
2019-08-13 12:11:30 +02:00
|
|
|
|
|
|
|
import * as installer from '../src/installer';
|
|
|
|
|
2019-08-16 13:31:13 +02:00
|
|
|
function osName(): string {
|
|
|
|
switch (process.platform) {
|
|
|
|
case 'win32':
|
|
|
|
return 'windows';
|
|
|
|
case 'darwin':
|
|
|
|
return 'macos';
|
|
|
|
default:
|
|
|
|
return process.platform;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-13 12:11:30 +02:00
|
|
|
describe('installer tests', () => {
|
|
|
|
beforeAll(async () => {
|
|
|
|
await io.rmRF(toolDir);
|
2019-08-13 12:23:34 +02:00
|
|
|
await io.rmRF(tempDir);
|
2019-08-13 12:11:30 +02:00
|
|
|
}, 300000);
|
|
|
|
|
|
|
|
afterAll(async () => {
|
|
|
|
try {
|
|
|
|
await io.rmRF(toolDir);
|
2019-08-13 12:23:34 +02:00
|
|
|
await io.rmRF(tempDir);
|
2019-08-13 12:11:30 +02:00
|
|
|
} catch {
|
|
|
|
console.log('Failed to remove test directories');
|
|
|
|
}
|
|
|
|
}, 100000);
|
|
|
|
|
|
|
|
it('Downloads flutter', async () => {
|
2019-08-16 13:40:47 +02:00
|
|
|
await installer.getFlutter('1.0.0', 'stable');
|
|
|
|
const sdkDir = path.join(toolDir, 'flutter', '1.0.0-stable', 'x64');
|
2019-08-13 12:11:30 +02:00
|
|
|
|
|
|
|
expect(fs.existsSync(`${sdkDir}.complete`)).toBe(true);
|
|
|
|
expect(fs.existsSync(path.join(sdkDir, 'bin'))).toBe(true);
|
|
|
|
}, 100000);
|
|
|
|
|
2019-08-18 16:23:51 +02:00
|
|
|
describe('get the latest release of a flutter version', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
const platform = osName();
|
|
|
|
nock('https://storage.googleapis.com', {allowUnmocked: true})
|
|
|
|
.get(`/flutter_infra/releases/releases_${platform}.json`)
|
|
|
|
.replyWithFile(200, path.join(dataDir, `releases_${platform}.json`));
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
nock.cleanAll();
|
|
|
|
nock.enableNetConnect();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('Downloads latest flutter release from stable channel', async () => {
|
|
|
|
await installer.getFlutter('', 'stable');
|
|
|
|
const sdkDir = path.join(
|
|
|
|
toolDir,
|
|
|
|
'flutter',
|
2020-04-14 03:07:07 +02:00
|
|
|
'1.12.13-hotfix.9-stable',
|
|
|
|
'x64'
|
|
|
|
);
|
|
|
|
|
|
|
|
expect(fs.existsSync(`${sdkDir}.complete`)).toBe(true);
|
|
|
|
expect(fs.existsSync(path.join(sdkDir, 'bin'))).toBe(true);
|
|
|
|
}, 200000);
|
|
|
|
|
|
|
|
it('Downloads latest flutter release from beta channel (using new release format)', async () => {
|
|
|
|
await installer.getFlutter('', 'beta');
|
|
|
|
const sdkDir = path.join(
|
|
|
|
toolDir,
|
|
|
|
'flutter',
|
|
|
|
'1.17.0-dev.3.1-beta',
|
2019-08-18 16:23:51 +02:00
|
|
|
'x64'
|
|
|
|
);
|
|
|
|
|
|
|
|
expect(fs.existsSync(`${sdkDir}.complete`)).toBe(true);
|
|
|
|
expect(fs.existsSync(path.join(sdkDir, 'bin'))).toBe(true);
|
2020-03-04 18:22:39 +01:00
|
|
|
}, 200000);
|
2019-08-18 16:23:51 +02:00
|
|
|
|
|
|
|
it('Downloads latest flutter release of 1.7 when using version 1.7 from dev channel', async () => {
|
|
|
|
await installer.getFlutter('1.7', 'dev');
|
|
|
|
const sdkDir = path.join(toolDir, 'flutter', '1.7.11-dev', 'x64');
|
|
|
|
|
|
|
|
expect(fs.existsSync(`${sdkDir}.complete`)).toBe(true);
|
|
|
|
expect(fs.existsSync(path.join(sdkDir, 'bin'))).toBe(true);
|
2020-03-04 18:22:39 +01:00
|
|
|
}, 200000);
|
2019-08-18 16:23:51 +02:00
|
|
|
|
|
|
|
it('Downloads latest flutter release of 1.7 when using version 1.7.x from dev channel', async () => {
|
|
|
|
await installer.getFlutter('1.7.x', 'dev');
|
|
|
|
const sdkDir = path.join(toolDir, 'flutter', '1.7.11-dev', 'x64');
|
|
|
|
|
|
|
|
expect(fs.existsSync(`${sdkDir}.complete`)).toBe(true);
|
|
|
|
expect(fs.existsSync(path.join(sdkDir, 'bin'))).toBe(true);
|
2020-03-04 18:22:39 +01:00
|
|
|
}, 200000);
|
2020-04-14 03:07:07 +02:00
|
|
|
|
|
|
|
it('Downloads latest flutter release of 1.18 when using version 1.18.x from dev channel (using new release format)', async () => {
|
|
|
|
await installer.getFlutter('1.18.x', 'dev');
|
|
|
|
const sdkDir = path.join(toolDir, 'flutter', '1.18.0-dev.5.0-dev', 'x64');
|
|
|
|
|
|
|
|
expect(fs.existsSync(`${sdkDir}.complete`)).toBe(true);
|
|
|
|
expect(fs.existsSync(path.join(sdkDir, 'bin'))).toBe(true);
|
|
|
|
}, 200000);
|
2019-08-18 16:23:51 +02:00
|
|
|
});
|
2019-08-16 10:34:20 +02:00
|
|
|
|
|
|
|
it('Throws if no location contains correct flutter version', async () => {
|
|
|
|
let thrown = false;
|
|
|
|
try {
|
|
|
|
await installer.getFlutter('1000.0', 'dev');
|
|
|
|
} catch {
|
|
|
|
thrown = true;
|
|
|
|
}
|
|
|
|
expect(thrown).toBe(true);
|
|
|
|
});
|
2019-08-13 12:11:30 +02:00
|
|
|
});
|