Expand node version file support to include lts based codenames

This commit is contained in:
Taylor McCarthy 2020-11-18 22:04:38 -05:00
parent c3812bd36a
commit a0d376d3fa
7 changed files with 311 additions and 43 deletions

View file

@ -0,0 +1,88 @@
import * as nv from '../src/node-version';
import * as nvf from '../src/node-version-file';
let nodeTestDist = require('./data/node-dist-index.json');
describe('node-version-file', () => {
let getVersionsFromDist: jest.SpyInstance;
beforeEach(() => {
// @actions/core
console.log('::stop-commands::stoptoken'); // Disable executing of runner commands when running tests in actions
getVersionsFromDist = jest.spyOn(nv, 'getVersionsFromDist');
// gets
getVersionsFromDist.mockImplementation(() => <nv.INodeVersion>nodeTestDist);
});
afterEach(() => {
jest.resetAllMocks();
jest.clearAllMocks();
//jest.restoreAllMocks();
});
afterAll(async () => {
console.log('::stoptoken::'); // Re-enable executing of runner commands when running tests in actions
}, 100000);
//--------------------------------------------------
// Manifest find tests
//--------------------------------------------------
describe('parseNodeVersionFile', () => {
it('without `v` prefix', async () => {
// Arrange
const versionSpec = '12';
// Act
const result = await nvf.parseNodeVersionFile(versionSpec);
// Assert
expect(result).toBe(versionSpec);
});
it('lts/*', async () => {
// Arrange
const versionSpec = 'lts/*';
// Act
const result = await nvf.parseNodeVersionFile(versionSpec);
// Assert
expect(result).toMatch(/^\d+\.\d+\.\d+$/);
});
it('lts/erbium', async () => {
// Arrange
const versionSpec = 'lts/*';
// Act
const result = await nvf.parseNodeVersionFile(versionSpec);
// Assert
expect(result).toMatch(/\d\.\d\.\d/);
});
it('partial syntax like 12', async () => {
// Arrange
const versionSpec = '12';
// Act
const result = await nvf.parseNodeVersionFile(versionSpec);
// Assert
expect(result).toBe(versionSpec);
});
it('partial syntax like 12.16', async () => {
// Arrange
const versionSpec = '12.16';
// Act
const result = await nvf.parseNodeVersionFile(versionSpec);
// Assert
expect(result).toBe(versionSpec);
});
});
});