env/index.test.js

72 lines
2 KiB
JavaScript
Raw Permalink Normal View History

2020-07-14 06:06:58 -04:00
const {
2020-07-16 05:13:18 -04:00
slugify, getRepositoryOwner, getRepositoryName, getRefName, getShaShort,
2020-07-14 06:06:58 -04:00
} = require('./index');
2020-07-16 05:13:18 -04:00
test('slugifies text', () => {
expect(slugify(' /abc+efg*123/test§xyz ')).toEqual('abc-efg-123-test-xyz');
});
2022-09-11 10:19:45 -04:00
test('slugifies a text to a maximum length', () => {
expect(slugify(' /abc+efg*123/test§xyz 1234567 /(ö) ', 16))
.toEqual('abc-efg-123-test');
});
test('slugifies a text to a maximum length with trailing dash', () => {
expect(slugify(' /abc+efg*123/test§xyz 1234567 /(ö) ', 17))
.toEqual('abc-efg-123-test');
});
2020-07-16 05:13:18 -04:00
test('slugifies ref name with dash', () => {
expect(slugify('feat/feature-branch-1')).toEqual('feat-feature-branch-1');
});
test('slugifies empty text', () => {
expect(slugify('')).toEqual('');
});
2020-07-14 06:06:58 -04:00
test('gets repository owner', () => {
expect(getRepositoryOwner('FranzDiebold/github-env-vars-action'))
.toEqual('FranzDiebold');
});
2020-11-30 14:33:02 -05:00
test('gets repository owner for empty repository', () => {
2020-07-14 06:06:58 -04:00
expect(getRepositoryOwner(undefined)).toBeFalsy();
});
2020-11-30 14:33:02 -05:00
test('gets repository name from repository', () => {
2020-07-14 06:06:58 -04:00
expect(getRepositoryName('FranzDiebold/github-env-vars-action'))
.toEqual('github-env-vars-action');
});
2020-11-30 14:33:02 -05:00
test('gets repository name for empty repository', () => {
2020-07-14 06:06:58 -04:00
expect(getRepositoryName(undefined)).toBeFalsy();
});
2020-11-30 14:33:02 -05:00
test('gets ref name from simple ref', () => {
2020-07-14 06:06:58 -04:00
expect(getRefName('refs/heads/feature-branch-1'))
.toEqual('feature-branch-1');
});
2020-11-30 14:33:02 -05:00
test('gets ref name from tag', () => {
expect(getRefName('refs/tags/v1.3.7'))
.toEqual('v1.3.7');
});
test('gets ref name from complex ref', () => {
2020-07-14 06:06:58 -04:00
expect(getRefName('refs/heads/feat/feature-branch-1'))
.toEqual('feat/feature-branch-1');
});
2020-11-30 14:33:02 -05:00
test('gets ref name for empty ref', () => {
2020-07-14 06:06:58 -04:00
expect(getRefName(undefined)).toBeFalsy();
});
test('gets short SHA', () => {
expect(getShaShort('ffac537e6cbbf934b08745a378932722df287a53'))
.toEqual('ffac537e');
});
2020-11-30 14:33:02 -05:00
test('gets short SHA for empty SHA', () => {
2020-07-14 06:06:58 -04:00
expect(getShaShort(undefined)).toBeFalsy();
});