1
1
import { describe , it , expect } from '@jest/globals' ;
2
- import { _generate_build_script , _generate_lint_script } from './scripts.js' ;
2
+
3
+ import {
4
+ _generate_build_script ,
5
+ _generate_lint_script ,
6
+ _generate_test_script ,
7
+ } from './scripts.js' ;
3
8
4
9
describe ( 'scripts' , ( ) => {
5
10
describe ( _generate_lint_script . name , ( ) => {
@@ -20,6 +25,7 @@ describe('scripts', () => {
20
25
} ) ;
21
26
22
27
test_no_shell_globs ( Object . values ( output . scripts ) ) ;
28
+ test_matched_braces ( Object . values ( output . scripts ) ) ;
23
29
} ) ;
24
30
25
31
describe ( `ts & js lint scripts` , ( ) => {
@@ -39,6 +45,7 @@ describe('scripts', () => {
39
45
} ) ;
40
46
41
47
test_no_shell_globs ( Object . values ( output . scripts ) ) ;
48
+ test_matched_braces ( Object . values ( output . scripts ) ) ;
42
49
} ) ;
43
50
44
51
describe ( `css lint scripts` , ( ) => {
@@ -55,6 +62,7 @@ describe('scripts', () => {
55
62
} ) ;
56
63
57
64
test_no_shell_globs ( Object . values ( output . scripts ) ) ;
65
+ test_matched_braces ( Object . values ( output . scripts ) ) ;
58
66
} ) ;
59
67
60
68
describe ( `css & scss lint scripts` , ( ) => {
@@ -72,38 +80,85 @@ describe('scripts', () => {
72
80
} ) ;
73
81
74
82
test_no_shell_globs ( Object . values ( output . scripts ) ) ;
83
+ test_matched_braces ( Object . values ( output . scripts ) ) ;
75
84
} ) ;
76
85
} ) ;
77
86
78
87
describe ( _generate_build_script . name , ( ) => {
79
- describe ( `ts lint scripts` , ( ) => {
88
+ describe ( `esbuild backend scripts` , ( ) => {
80
89
const output = _generate_build_script ( {
81
- project_type : 'web-app ' ,
90
+ project_type : 'backend ' ,
82
91
builder : 'esbuild' ,
83
92
languages : [ 'ts' ] ,
84
- technologies : [ 'react ' ] ,
93
+ technologies : [ 'esm ' ] ,
85
94
library : false ,
86
- input_dir : 'src/ ' ,
87
- output_dir : 'dist/ ' ,
95
+ input_dir : 'src' ,
96
+ output_dir : 'dist' ,
88
97
} ) ;
89
98
90
99
it ( `should create build scripts` , ( ) => {
91
100
expect ( output . scripts . build ) . toMatch ( / c o n c u r r e n t l y .+ ' n p m : b u i l d : \* ' / u) ;
92
101
expect ( output . scripts [ 'build:js' ] ) . toMatch ( / ^ e s b u i l d / u) ;
102
+ expect ( output . scripts [ 'build:js' ] ) . toMatch ( / \b e s m \b / u) ;
93
103
expect ( output . scripts [ 'build:js' ] ) . not . toMatch ( / \n / u) ;
94
104
} ) ;
95
105
96
106
test_no_shell_globs ( Object . values ( output . scripts ) ) ;
107
+ test_matched_braces ( Object . values ( output . scripts ) ) ;
108
+ } ) ;
109
+ } ) ;
110
+
111
+ describe ( _generate_test_script . name , ( ) => {
112
+ describe ( `test scripts using node:test with esbuild` , ( ) => {
113
+ const output = _generate_test_script ( {
114
+ builder : 'esbuild' ,
115
+ languages : [ 'ts' ] ,
116
+ technologies : [ 'esm' ] ,
117
+ output_dir : 'dist' ,
118
+ runtime : 'nodejs' ,
119
+ } ) ;
120
+
121
+ it ( `should create build scripts` , ( ) => {
122
+ expect ( output . scripts . test ) . toMatch ( / ^ n o d e .* - - t e s t / u) ;
123
+ expect ( output . scripts [ 'test:debug' ] ) . toMatch ( / - - i n s p e c t - b r k / u) ;
124
+ expect ( output . scripts [ 'test:debug' ] ) . not . toMatch ( / N O D E _ O P T I O N S = / u) ;
125
+ } ) ;
126
+
127
+ test_no_shell_globs ( Object . values ( output . scripts ) ) ;
128
+ test_matched_braces ( Object . values ( output . scripts ) ) ;
97
129
} ) ;
98
130
} ) ;
99
131
} ) ;
100
132
101
- function test_no_shell_globs ( scripts : string [ ] ) {
133
+ export function test_no_shell_globs ( scripts : string [ ] ) {
102
134
// eslint-disable-next-line jest/require-top-level-describe
103
135
it ( `shouldn't allow the shell to expand globs` , ( ) => {
136
+ expect . hasAssertions ( ) ;
137
+ // expect.assertions(scripts.length);
138
+
104
139
for ( const script of scripts ) {
105
140
// https://regex101.com/r/e67boW/
106
141
expect ( script ) . toMatch ( / (?: [ " ' ] [ \S ] * ?( \* ) [ \S ] * ?[ " ' ] | ^ [ ^ * ] * $ ) / u) ;
107
142
}
108
143
} ) ;
109
144
}
145
+
146
+ export function test_matched_braces ( scripts : string [ ] ) {
147
+ // eslint-disable-next-line jest/require-top-level-describe
148
+ it ( `should match opening & closing braces` , ( ) => {
149
+ expect . hasAssertions ( ) ;
150
+ // expect.assertions(scripts.length * 3);
151
+
152
+ for ( const script of scripts ) {
153
+ expect ( script . match ( / \( / gu) ?. length ) . toEqual (
154
+ script . match ( / \) / gu) ?. length ,
155
+ ) ;
156
+ expect ( script . match ( / \[ / gu) ?. length ) . toEqual (
157
+ script . match ( / \] / gu) ?. length ,
158
+ ) ;
159
+ expect ( script . match ( / \{ / gu) ?. length ) . toEqual (
160
+ script . match ( / \} / gu) ?. length ,
161
+ ) ;
162
+ }
163
+ } ) ;
164
+ }
0 commit comments