11import { 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