Skip to content

Commit

Permalink
add simple tests to semver
Browse files Browse the repository at this point in the history
  • Loading branch information
peter-svensson committed Sep 30, 2021
1 parent a910e55 commit db7e5ca
Show file tree
Hide file tree
Showing 7 changed files with 17,578 additions and 107 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules/
lib
coverage
14 changes: 14 additions & 0 deletions __tests__/semver.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import {semver} from '../src/main';

test('simple versions', async () => {
expect(await semver('v1.13.1')).toBe('1.13.1');
expect(await semver('1.13.1')).toBe('1.13.1');
expect(await semver('1.13')).toBe('1.13.0');
});

test('pre-release versions', async () => {
expect(await semver('1.10beta1')).toBe('1.10.0-beta1');
expect(await semver('1.10-beta1')).toBe('1.10.0-beta1');
expect(await semver('1.8.5rc1')).toBe('1.8.5-rc1');
expect(await semver('0.2.0-beta.1')).toBe('0.2.0-beta.1');
});
5 changes: 4 additions & 1 deletion dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1548,7 +1548,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.addBinToPath = exports.run = void 0;
exports.resolveLatestVersion = exports.semver = exports.addBinToPath = exports.run = void 0;
const core = __importStar(__webpack_require__(470));
const httpm = __importStar(__webpack_require__(539));
const io = __importStar(__webpack_require__(1));
Expand Down Expand Up @@ -1597,6 +1597,7 @@ async function semver(version) {
version = version.replace('beta', '-beta').replace('rc', '-rc');
}
version = version.replace('v', '');
version = version.replace('--', '-');
let parts = version.split('-');
let verPart = parts[0];
let prereleasePart = parts.length > 1 ? `-${parts[1]}` : '';
Expand All @@ -1606,6 +1607,7 @@ async function semver(version) {
}
return `${verPart}${prereleasePart}`;
}
exports.semver = semver;
async function resolveLatestVersion() {
let _http = new httpm.HttpClient('build-tools setup');
let res = await _http.get('https://api.github.com/repos/buildtool/build-tools/releases/latest');
Expand All @@ -1619,6 +1621,7 @@ async function resolveLatestVersion() {
core.info(`Got buildtools version latest => ${version}`);
return version;
}
exports.resolveLatestVersion = resolveLatestVersion;


/***/ }),
Expand Down
11 changes: 11 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module.exports = {
clearMocks: true,
moduleFileExtensions: ['js', 'ts'],
testEnvironment: 'node',
testMatch: ['**/*.test.ts'],
testRunner: 'jest-circus/runner',
transform: {
'^.+\\.ts$': 'ts-jest'
},
verbose: true
}
Loading

0 comments on commit db7e5ca

Please sign in to comment.