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

77 lines
2.2 KiB
TypeScript
Raw Normal View History

2019-08-13 12:11:30 +02:00
import io = require('@actions/io');
2020-10-08 06:36:23 +02:00
import exec = require('@actions/exec');
2019-08-13 12:11:30 +02:00
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';
2020-10-08 03:22:27 +02:00
import * as release from '../src/release';
2019-08-16 13:31:13 +02:00
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);
2020-10-08 03:32:27 +02:00
}, 100000);
2020-10-08 03:22:27 +02:00
beforeEach(() => {
const platform = release.getPlatform();
nock('https://storage.googleapis.com', {allowUnmocked: true})
.get(`/flutter_infra/releases/releases_${platform}.json`)
.replyWithFile(200, path.join(dataDir, `releases_${platform}.json`));
});
2019-08-13 12:11:30 +02:00
2020-04-14 03:47:20 +02:00
afterEach(async () => {
2020-10-08 03:22:27 +02:00
nock.cleanAll();
nock.enableNetConnect();
2020-04-14 03:47:20 +02:00
await io.rmRF(toolDir);
await io.rmRF(tempDir);
2020-10-08 03:32:27 +02:00
}, 100000);
2020-04-14 03:47:20 +02:00
2019-08-13 12:11:30 +02:00
it('Downloads flutter', async () => {
2021-04-26 16:24:40 +02:00
await installer.getFlutter('2.0.0', 'stable');
const sdkDir = path.join(toolDir, 'flutter', '2.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);
2020-04-14 04:05:13 +02:00
}, 300000);
2019-08-13 12:11:30 +02:00
2020-10-08 06:36:23 +02:00
it('Downloads flutter from master channel', async () => {
await installer.getFlutter('', 'master');
const sdkDir = path.join(toolDir, 'flutter', 'master', 'x64');
let stdout = '';
const options = {
listeners: {
stdout: (data: Buffer) => {
stdout += data.toString();
}
}
};
expect(fs.existsSync(`${sdkDir}.complete`)).toBe(true);
expect(fs.existsSync(path.join(sdkDir, 'bin'))).toBe(true);
await exec.exec(path.join(sdkDir, 'bin', 'flutter'), ['channel'], options);
expect(stdout).toContain('* master');
}, 300000);
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
});