Skip to content

Commit 7340e00

Browse files
committed
🐛 add missing parenthesis
1 parent ff18fdf commit 7340e00

File tree

2 files changed

+75
-19
lines changed

2 files changed

+75
-19
lines changed

packages/create-configs/src/steps/scripts.spec.ts

Lines changed: 62 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
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';
38

49
describe('scripts', () => {
510
describe(_generate_lint_script.name, () => {
@@ -20,6 +25,7 @@ describe('scripts', () => {
2025
});
2126

2227
test_no_shell_globs(Object.values(output.scripts));
28+
test_matched_braces(Object.values(output.scripts));
2329
});
2430

2531
describe(`ts & js lint scripts`, () => {
@@ -39,6 +45,7 @@ describe('scripts', () => {
3945
});
4046

4147
test_no_shell_globs(Object.values(output.scripts));
48+
test_matched_braces(Object.values(output.scripts));
4249
});
4350

4451
describe(`css lint scripts`, () => {
@@ -55,6 +62,7 @@ describe('scripts', () => {
5562
});
5663

5764
test_no_shell_globs(Object.values(output.scripts));
65+
test_matched_braces(Object.values(output.scripts));
5866
});
5967

6068
describe(`css & scss lint scripts`, () => {
@@ -72,38 +80,85 @@ describe('scripts', () => {
7280
});
7381

7482
test_no_shell_globs(Object.values(output.scripts));
83+
test_matched_braces(Object.values(output.scripts));
7584
});
7685
});
7786

7887
describe(_generate_build_script.name, () => {
79-
describe(`ts lint scripts`, () => {
88+
describe(`esbuild backend scripts`, () => {
8089
const output = _generate_build_script({
81-
project_type: 'web-app',
90+
project_type: 'backend',
8291
builder: 'esbuild',
8392
languages: ['ts'],
84-
technologies: ['react'],
93+
technologies: ['esm'],
8594
library: false,
86-
input_dir: 'src/',
87-
output_dir: 'dist/',
95+
input_dir: 'src',
96+
output_dir: 'dist',
8897
});
8998

9099
it(`should create build scripts`, () => {
91100
expect(output.scripts.build).toMatch(/concurrently.+'npm:build:\*'/u);
92101
expect(output.scripts['build:js']).toMatch(/^esbuild /u);
102+
expect(output.scripts['build:js']).toMatch(/\besm\b/u);
93103
expect(output.scripts['build:js']).not.toMatch(/\n/u);
94104
});
95105

96106
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(/^node .*--test/u);
123+
expect(output.scripts['test:debug']).toMatch(/--inspect-brk/u);
124+
expect(output.scripts['test:debug']).not.toMatch(/NODE_OPTIONS=/u);
125+
});
126+
127+
test_no_shell_globs(Object.values(output.scripts));
128+
test_matched_braces(Object.values(output.scripts));
97129
});
98130
});
99131
});
100132

101-
function test_no_shell_globs(scripts: string[]) {
133+
export function test_no_shell_globs(scripts: string[]) {
102134
// eslint-disable-next-line jest/require-top-level-describe
103135
it(`shouldn't allow the shell to expand globs`, () => {
136+
expect.hasAssertions();
137+
// expect.assertions(scripts.length);
138+
104139
for (const script of scripts) {
105140
// https://regex101.com/r/e67boW/
106141
expect(script).toMatch(/(?:["'][\S]*?(\*)[\S]*?["']|^[^*]*$)/u);
107142
}
108143
});
109144
}
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+
}

packages/create-configs/src/steps/scripts.ts

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,7 @@ export function _generate_build_script({
137137
--tsconfig=tsconfig.build.json
138138
$(${deps.d.depend('glob')}
139139
'${input_dir}/**/*.?(c|m)[jt]s'
140-
--ignore '${test_file_glob}'
141-
)
140+
--ignore '${test_file_glob}')
142141
--outdir=${output_dir}
143142
--sourcemap=inline
144143
--platform=${project_type !== 'web-app' ? 'node' : 'browser'}
@@ -271,16 +270,18 @@ export function _generate_test_script({
271270
[
272271
`node $NODE_OPTS --import=${deps.d.depend('tsx')}`,
273272
`--test $(${deps.d.depend('glob')}`,
274-
...['**/node_modules/**', `**/${output_dir}/**`].map(
275-
(ig) => `--ignore '${ig}'`,
276-
),
277-
...[
278-
// Based on the default test file patterns:
279-
// https://nodejs.org/api/test.html#running-tests-from-the-command-line
280-
`'**/*[.-_]test.?(c|m)[jt]s'`,
281-
`'**/test?(-*).?(c|m)[jt]s'`,
282-
`'**/test/**/*.?(c|m)[jt]s'`,
283-
],
273+
[
274+
...['**/node_modules/**', `**/${output_dir}/**`].map(
275+
(ig) => `--ignore '${ig}'`,
276+
),
277+
...[
278+
// Based on the default test file patterns:
279+
// https://nodejs.org/api/test.html#running-tests-from-the-command-line
280+
`'**/*[.-_]test.?(c|m)[jt]s'`,
281+
`'**/test?(-*).?(c|m)[jt]s'`,
282+
`'**/test/**/*.?(c|m)[jt]s'`,
283+
],
284+
].join(' ') + ')',
284285
].join(' '),
285286
].join('; '),
286287
'test:debug': `NODE_OPTS='--inspect-brk' npm run test`,

0 commit comments

Comments
 (0)