Skip to content

Commit 9ab5023

Browse files
committed
Debug
1 parent 1d2878d commit 9ab5023

2 files changed

Lines changed: 26 additions & 6 deletions

File tree

bin/generate-npm-tag.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,16 @@ HIGHEST_PUBLISHED_VERSION=${2:-$(git tag --list 2>/dev/null | sort -V | tail -n1
99

1010
version() { echo "$@" | awk -F. '{ printf("%d%03d%03d\n", $1,$2,$3); }'; }
1111

12+
echo $CURRENT_VERSION
13+
echo $HIGHEST_PUBLISHED_VERSION
14+
echo $(git tag --list 2>/dev/null | sort -V | tail -n1 2>/dev/null | sed 's/v//g')
15+
1216
if [ "$CURRENT_VERSION" = "$HIGHEST_PUBLISHED_VERSION" ]; then
1317
echo "⚠️ Git tag $CURRENT_VERSION already exists. Check you have run \`npm version\` correctly."
1418
exit 1
1519
elif echo "$CURRENT_VERSION" | grep -q "internal"; then
1620
NPM_TAG="internal"
17-
elif echo "$CURRENT_VERSION" | grep -q -E '^\d+\.\d+\.\d+-\D+(\.\d+)?$'; then
21+
elif echo "$CURRENT_VERSION" | grep -q "-"; then
1822
NPM_TAG="next"
1923
elif [ $(version "$CURRENT_VERSION") -ge $(version "$HIGHEST_PUBLISHED_VERSION") ]; then
2024
NPM_TAG="latest"

bin/generate-npm-tag.unit.test.mjs

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
import { exec } from 'node:child_process'
22

3-
describe('generate-npm-tag.sh', () => {
4-
it('errors if the version in the GOV.UK Frontend package is currently published', async () => {
3+
// Our build scripts are Shell scripts so won't run on Windows
4+
// Unfortunately, Jest wants test files to have test suites,
5+
// so we need to only run `describe` if the platform is not Windows
6+
describeIf(process.platform !== 'win32')('generate-npm-tag.sh', () => {
7+
it.only('errors if the version in the GOV.UK Frontend package is currently published', async () => {
58
expect.assertions(2)
69
// Unfortunately Jest's `.rejects.toThrow` only allows to test the type of error or its message
710
// so we need to explicitly `try/catch` to check the exit code and message
811
try {
9-
await execute('bin/generate-npm-tag.sh')
12+
await execute('bin/generate-npm-tag.sh 6.2.0-beta.0 6.2.0-beta.0')
1013
} catch (e) {
1114
expect(e.code).toBe(1)
1215
expect(e.stdout).toMatch(
@@ -22,8 +25,8 @@ describe('generate-npm-tag.sh', () => {
2225
['minor', '6.1.0', 'latest'],
2326
['major', '7.0.0', 'latest'],
2427
['internal', '6.0.0-internal', 'internal'],
25-
['beta', '6.0.0-beta', 'next'],
26-
['rc', '6.0.0-rc', 'next'],
28+
['beta', '6.1.0-beta.0', 'next'],
29+
['rc', '6.1.0-rc.1', 'next'],
2730
['latest-...', '4.0.0', 'latest-v4']
2831
])('%s bump', async (label, version, expectedTag) => {
2932
const { stdout } = await execute(
@@ -34,6 +37,19 @@ describe('generate-npm-tag.sh', () => {
3437
})
3538
})
3639

40+
/**
41+
* Allows to skip a `describe` block if the condition is not met
42+
*
43+
* Jest does not allow empty test suites, so this allows to skip all tests
44+
* if a condition is met
45+
*
46+
* @param {boolean} condition - The condition that needs to be met for tests to run
47+
* @returns {Function} Jest's `describe` function if the `condition` is met, `describe.skip` otherwise
48+
*/
49+
function describeIf(condition) {
50+
return condition ? describe : describe.skip
51+
}
52+
3753
/**
3854
* Executes the given command and returns the content of `stdout` and `stderr`
3955
*

0 commit comments

Comments
 (0)