Files
setup-ruby/__tests__/find-ruby.test.ts
Stephen Franceschelli e3283467a1 Fix bug. Add workflows.
2019-07-15 13:23:24 -04:00

60 lines
1.6 KiB
TypeScript

import * as io from '@actions/io';
import fs = require('fs');
import os = require('os');
import path = require('path');
const toolDir = path.join(__dirname, 'runner', 'tools');
const tempDir = path.join(__dirname, 'runner', 'temp');
process.env['RUNNER_TOOLSDIRECTORY'] = toolDir;
process.env['RUNNER_TEMPDIRECTORY'] = tempDir;
import {findRubyVersion} from '../src/installer';
describe('find-ruby', () => {
beforeAll(async () => {
await io.rmRF(toolDir);
await io.rmRF(tempDir);
});
afterAll(async () => {
try {
await io.rmRF(toolDir);
await io.rmRF(tempDir);
} catch {
console.log('Failed to remove test directories');
}
}, 100000);
it('findRubyVersion throws if cannot find any version of ruby', async () => {
let thrown = false;
try {
await findRubyVersion('2.4.6');
} catch {
thrown = true;
}
expect(thrown).toBe(true);
});
it('findRubyVersion throws version of ruby is not complete', async () => {
let thrown = false;
const rubyDir: string = path.join(toolDir, 'Ruby', '2.4.6', os.arch());
await io.mkdirP(rubyDir);
try {
await findRubyVersion('2.4.6');
} catch {
thrown = true;
}
expect(thrown).toBe(true);
});
it('findRubyVersion adds ruby bin to PATH', async () => {
const rubyDir: string = path.join(toolDir, 'Ruby', '2.4.6', os.arch());
await io.mkdirP(rubyDir);
fs.writeFileSync(`${rubyDir}.complete`, 'hello');
await findRubyVersion('2.4.6');
const binDir = path.join(rubyDir, 'bin');
expect(process.env['PATH']!.startsWith(`${binDir};`)).toBe(true);
});
});