Skip to content

Commit c16e858

Browse files
authored
fix: avoid adding WASM example without DOM definitions (#244)
also add tooling for reviewing integration test results fix #243
1 parent 7432704 commit c16e858

8 files changed

Lines changed: 104 additions & 29 deletions

File tree

‎.circleci/config.yml‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ jobs:
1818
- node_modules
1919
key: v1-dependencies-{{ checksum "package.json" }}
2020
- run: npm test
21+
- run: npm run check-integration-tests
2122
- run: npm run cov:send
2223
- run: npm run cov:check
2324
'node-12':
@@ -35,6 +36,7 @@ jobs:
3536
- node_modules
3637
key: v1-dependencies-{{ checksum "package.json" }}
3738
- run: npm test
39+
- run: npm run check-integration-tests
3840
- run: npm run cov:send
3941
- run: npm run cov:check
4042
'node-latest':
@@ -52,6 +54,7 @@ jobs:
5254
- node_modules
5355
key: v1-dependencies-{{ checksum "package.json" }}
5456
- run: npm test
57+
- run: npm run check-integration-tests
5558
- run: npm run cov:send
5659
- run: npm run cov:check
5760

‎.cspell.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"commitlint",
1212
"dependabot",
1313
"editorconfig",
14+
"esnext",
1415
"execa",
1516
"exponentiate",
1617
"globby",

‎.gitignore‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.cache
1+
diff
22
.idea/*
33
.nyc_output
44
build

‎README.md‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,8 @@ npm test
311311
npm link
312312
```
313313

314+
### Manual testing
315+
314316
To manually test the CLI, you can use the `TYPESCRIPT_STARTER_REPO_URL` environment variable to test a clone from your local repo. Run `npm run build:main -- -w` as you're developing, then in a different testing directory:
315317

316318
```
@@ -327,6 +329,24 @@ TYPESCRIPT_STARTER_REPO_URL='https://github.com/YOUR_USERNAME/typescript-starter
327329

328330
If `TYPESCRIPT_STARTER_REPO_BRANCH` is not provided, it will default to `master`.
329331

332+
### Debug in VS Code
333+
330334
If you're using [VS Code](https://code.visualstudio.com/), the `Debug CLI` launch configuration also allows you to immediately build and step through execution of the CLI.
331335

336+
### Integration Test Result Diffs
337+
338+
You can compare the integration test results before and after a change by running `check-cli` before and after applying your changes:
339+
340+
```sh
341+
npm run check-cli
342+
```
343+
344+
Each time you run `check-cli`, the test results will be committed to the `diff` directory, allowing you to easily review the differences with `git diff HEAD` or an interactive Git client like [GitHub for Desktop](https://desktop.github.com/) or [SourceTree](https://www.sourcetreeapp.com/).
345+
346+
If you already have changes in the working directory, try:
347+
348+
```sh
349+
git stash && npm run check-cli && git stash pop && npm run check-cli
350+
```
351+
332352
</details>

‎package.json‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,21 @@
3434
"build:module": "tsc -p tsconfig.module.json",
3535
"fix": "run-s fix:*",
3636
"fix:prettier": "prettier \"src/**/*.ts\" --write",
37-
"fix:lint": "eslint . --ext .ts --fix",
37+
"fix:lint": "eslint src --ext .ts --fix",
3838
"test": "run-s build test:*",
3939
"test:lint": "eslint src --ext .ts",
4040
"test:prettier": "prettier \"src/**/*.ts\" --list-different",
4141
"test:spelling": "cspell \"{README.md,.github/*.md,src/**/*.ts}\"",
4242
"test:unit": "nyc --silent ava",
43+
"check-cli": "run-s test diff-integration-tests check-integration-tests",
44+
"check-integration-tests": "run-s check-integration-test:*",
45+
"check-integration-test:1": "cd test/test-1 && npm i && npm run build && npm run test",
46+
"check-integration-test:2": "cd test/test-2 && yarn && yarn build && yarn test",
47+
"check-integration-test:3": "cd test/test-3 && yarn && yarn build && yarn test",
48+
"check-integration-test:4": "cd test/test-4 && npm i && npm run build && npm run test",
49+
"check-integration-test:5": "cd test/test-5 && npm i && npm run build && npm run test",
50+
"check-integration-test:6": "cd test/test-6 && yarn && yarn build && yarn test",
51+
"diff-integration-tests": "mkdir -p diff && rm -rf diff/test && cp -r test diff/test && rm -rf diff/test/test-*/.git && cd diff && git init --quiet && git add -A && git commit --quiet --no-verify --allow-empty -m 'WIP' && echo '\\n\\nCommitted most recent integration test output in the \"diff\" directory. Review the changes with \"cd diff && git diff HEAD\" or your preferred git diff viewer.'",
4352
"watch:build": "tsc -p tsconfig.json -w",
4453
"watch:test": "nyc --silent ava --watch",
4554
"cov": "run-s build test:unit cov:html cov:lcov && open-cli coverage/index.html",
@@ -125,10 +134,12 @@
125134
}
126135
},
127136
"files": [
137+
"!diff",
128138
"!test",
129139
"!build/module/**"
130140
],
131141
"ignoredByWatcher": [
142+
"diff",
132143
"test"
133144
]
134145
},

‎src/cli/tests/cli.integration.spec.ts‎

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -158,14 +158,14 @@ test(`${TestDirectories.one}: parses CLI arguments, handles default options`, as
158158
const map = await hashAllTheThings(TestDirectories.one);
159159
t.deepEqual(map, {
160160
'test-1/.circleci/config.yml': '44d2fd424c93d381d41030f789efabba',
161-
'test-1/.cspell.json': '5b2e0ad337bc05ef2ce5635270d983fd',
161+
'test-1/.cspell.json': '61bbd8ed98375a94cbd1063ab498959f',
162162
'test-1/.editorconfig': '44a3e6c69d9267b0f756986fd970a8f4',
163163
'test-1/.eslintrc.json': '4e74756d24eaccb7f28d4999e4bd6f0d',
164164
'test-1/.github/CONTRIBUTING.md': '5f0dfa7fdf9bf828e3a3aa8fcaeece08',
165165
'test-1/.github/ISSUE_TEMPLATE.md': 'e70a0b70402765682b1a961af855040e',
166166
'test-1/.github/PULL_REQUEST_TEMPLATE.md':
167167
'70f4b97f3914e2f399bcc5868e072c29',
168-
'test-1/.gitignore': '96abf7aadc9155ba2a5bba1e05563ff0',
168+
'test-1/.gitignore': 'a053cd9512af2ebf8ffac400b14034eb',
169169
'test-1/.prettierignore': '1da1ce4fdb868f0939608fafd38f9683',
170170
'test-1/.vscode/extensions.json': '2d26a716ba181656faac4cd2d38ec139',
171171
'test-1/.vscode/launch.json': '140e17d591e03b8850c456ade3aefb1f',
@@ -175,7 +175,7 @@ test(`${TestDirectories.one}: parses CLI arguments, handles default options`, as
175175
'test-1/src/lib/number.spec.ts': '0592001d71aa3b3e6bf72f4cd95dc1b9',
176176
'test-1/src/lib/number.ts': 'dcbcc98fea337d07e81728c1a6526a1e',
177177
'test-1/src/types/example.d.ts': '76642861732b16754b0110fb1de49823',
178-
'test-1/tsconfig.json': '741e6fa9f78712a6f276ba33fc2c798b',
178+
'test-1/tsconfig.json': '4228782ef56faca96f8123a88bf26dc2',
179179
'test-1/tsconfig.module.json': '2fda4c8760c6cfa3462b40df0645850d',
180180
});
181181
});
@@ -203,14 +203,14 @@ test(`${TestDirectories.two}: parses CLI arguments, handles all options`, async
203203
const map = await hashAllTheThings(TestDirectories.two);
204204
t.deepEqual(map, {
205205
'test-2/.circleci/config.yml': '44d2fd424c93d381d41030f789efabba',
206-
'test-2/.cspell.json': '5b2e0ad337bc05ef2ce5635270d983fd',
206+
'test-2/.cspell.json': '61bbd8ed98375a94cbd1063ab498959f',
207207
'test-2/.editorconfig': '44a3e6c69d9267b0f756986fd970a8f4',
208208
'test-2/.eslintrc.json': '4e74756d24eaccb7f28d4999e4bd6f0d',
209209
'test-2/.github/CONTRIBUTING.md': '5f0dfa7fdf9bf828e3a3aa8fcaeece08',
210210
'test-2/.github/ISSUE_TEMPLATE.md': 'e70a0b70402765682b1a961af855040e',
211211
'test-2/.github/PULL_REQUEST_TEMPLATE.md':
212212
'70f4b97f3914e2f399bcc5868e072c29',
213-
'test-2/.gitignore': '2b90e204ba76e30ec95f946ac7c9787e',
213+
'test-2/.gitignore': '703beedaf3cabd7f7fd7d3f57408ec61',
214214
'test-2/.prettierignore': '1da1ce4fdb868f0939608fafd38f9683',
215215
'test-2/.vscode/extensions.json': '2d26a716ba181656faac4cd2d38ec139',
216216
'test-2/.vscode/launch.json': '140e17d591e03b8850c456ade3aefb1f',
@@ -224,7 +224,7 @@ test(`${TestDirectories.two}: parses CLI arguments, handles all options`, async
224224
'test-2/src/lib/number.spec.ts': '0592001d71aa3b3e6bf72f4cd95dc1b9',
225225
'test-2/src/lib/number.ts': 'dcbcc98fea337d07e81728c1a6526a1e',
226226
'test-2/src/types/example.d.ts': '76642861732b16754b0110fb1de49823',
227-
'test-2/tsconfig.json': 'eadf0f5640c5000ceabf242d157861e4',
227+
'test-2/tsconfig.json': '7a9481f033cb07985ee1b903ad42b167',
228228
'test-2/tsconfig.module.json': '2fda4c8760c6cfa3462b40df0645850d',
229229
});
230230
});
@@ -288,14 +288,14 @@ test(`${TestDirectories.three}: interactive mode: javascript library`, async (t)
288288
const map = await hashAllTheThings(TestDirectories.three);
289289
t.deepEqual(map, {
290290
'test-3/.circleci/config.yml': '44d2fd424c93d381d41030f789efabba',
291-
'test-3/.cspell.json': '5b2e0ad337bc05ef2ce5635270d983fd',
291+
'test-3/.cspell.json': '61bbd8ed98375a94cbd1063ab498959f',
292292
'test-3/.editorconfig': '44a3e6c69d9267b0f756986fd970a8f4',
293293
'test-3/.eslintrc.json': '4e74756d24eaccb7f28d4999e4bd6f0d',
294294
'test-3/.github/CONTRIBUTING.md': '5f0dfa7fdf9bf828e3a3aa8fcaeece08',
295295
'test-3/.github/ISSUE_TEMPLATE.md': 'e70a0b70402765682b1a961af855040e',
296296
'test-3/.github/PULL_REQUEST_TEMPLATE.md':
297297
'70f4b97f3914e2f399bcc5868e072c29',
298-
'test-3/.gitignore': '2b90e204ba76e30ec95f946ac7c9787e',
298+
'test-3/.gitignore': '703beedaf3cabd7f7fd7d3f57408ec61',
299299
'test-3/.prettierignore': '1da1ce4fdb868f0939608fafd38f9683',
300300
'test-3/.vscode/extensions.json': '2d26a716ba181656faac4cd2d38ec139',
301301
'test-3/.vscode/launch.json': '140e17d591e03b8850c456ade3aefb1f',
@@ -309,7 +309,7 @@ test(`${TestDirectories.three}: interactive mode: javascript library`, async (t)
309309
'test-3/src/lib/number.spec.ts': '0592001d71aa3b3e6bf72f4cd95dc1b9',
310310
'test-3/src/lib/number.ts': 'dcbcc98fea337d07e81728c1a6526a1e',
311311
'test-3/src/types/example.d.ts': '76642861732b16754b0110fb1de49823',
312-
'test-3/tsconfig.json': '25e6e53cdc0b9194c5ba862b275afc37',
312+
'test-3/tsconfig.json': '472791a7b88cee5b9369207216fe7f98',
313313
'test-3/tsconfig.module.json': '2fda4c8760c6cfa3462b40df0645850d',
314314
});
315315
});
@@ -326,28 +326,26 @@ test(`${TestDirectories.four}: interactive mode: node.js application`, async (t)
326326
const map = await hashAllTheThings(TestDirectories.four);
327327
t.deepEqual(map, {
328328
'test-4/.circleci/config.yml': '44d2fd424c93d381d41030f789efabba',
329-
'test-4/.cspell.json': '5b2e0ad337bc05ef2ce5635270d983fd',
329+
'test-4/.cspell.json': '61bbd8ed98375a94cbd1063ab498959f',
330330
'test-4/.editorconfig': '44a3e6c69d9267b0f756986fd970a8f4',
331331
'test-4/.eslintrc.json': '941448b089cd055bbe476a84c8f96cfe',
332332
'test-4/.github/CONTRIBUTING.md': '5f0dfa7fdf9bf828e3a3aa8fcaeece08',
333333
'test-4/.github/ISSUE_TEMPLATE.md': 'e70a0b70402765682b1a961af855040e',
334334
'test-4/.github/PULL_REQUEST_TEMPLATE.md':
335335
'70f4b97f3914e2f399bcc5868e072c29',
336-
'test-4/.gitignore': '96abf7aadc9155ba2a5bba1e05563ff0',
336+
'test-4/.gitignore': 'a053cd9512af2ebf8ffac400b14034eb',
337337
'test-4/.prettierignore': '1da1ce4fdb868f0939608fafd38f9683',
338338
'test-4/.vscode/extensions.json': '2d26a716ba181656faac4cd2d38ec139',
339339
'test-4/.vscode/launch.json': '140e17d591e03b8850c456ade3aefb1f',
340340
'test-4/.vscode/settings.json': '1671948882faee285f18d7491f0fc913',
341341
'test-4/README.md': 'a3e0699b39498df4843c9dde95f1e000',
342-
'test-4/src/index.ts': 'fbc67c2cbf3a7d37e4e02583bf06eec9',
342+
'test-4/src/index.ts': '5991bedc40ac87a01d880c6db16fe349',
343343
'test-4/src/lib/async.spec.ts': '65b10546885ebad41c098318b896f23c',
344344
'test-4/src/lib/async.ts': '926732fef1285cb0abb5c6e287ed24df',
345-
'test-4/src/lib/hash.spec.ts': '06f6bfc1b03f893a16448bb6d6806ea2',
346-
'test-4/src/lib/hash.ts': 'cf3659937ff3162bc525c8bfac18b7cf',
347345
'test-4/src/lib/number.spec.ts': '0592001d71aa3b3e6bf72f4cd95dc1b9',
348346
'test-4/src/lib/number.ts': 'dcbcc98fea337d07e81728c1a6526a1e',
349347
'test-4/src/types/example.d.ts': '76642861732b16754b0110fb1de49823',
350-
'test-4/tsconfig.json': '0256ae9ca8952a1125c461392b69ce06',
348+
'test-4/tsconfig.json': 'b4786d3cf1c3e6bd51253c036bfc6e8a',
351349
'test-4/tsconfig.module.json': '2fda4c8760c6cfa3462b40df0645850d',
352350
});
353351
});
@@ -413,15 +411,15 @@ test(`${TestDirectories.five}: Sandboxed: npm install, initial commit`, async (t
413411
'test-5/.github/ISSUE_TEMPLATE.md': 'e70a0b70402765682b1a961af855040e',
414412
'test-5/.github/PULL_REQUEST_TEMPLATE.md':
415413
'70f4b97f3914e2f399bcc5868e072c29',
416-
'test-5/.gitignore': '96abf7aadc9155ba2a5bba1e05563ff0',
414+
'test-5/.gitignore': 'a053cd9512af2ebf8ffac400b14034eb',
417415
'test-5/.prettierignore': '1da1ce4fdb868f0939608fafd38f9683',
418416
'test-5/LICENSE': '317693126d229a3cdd19725a624a56fc',
419417
'test-5/README.md': '8fc7ecb21d7d47289e4b2469eea4db39',
420418
'test-5/src/index.ts': '5025093b4dc30524d349fd1cc465ed30',
421419
'test-5/src/lib/number.spec.ts': '0592001d71aa3b3e6bf72f4cd95dc1b9',
422420
'test-5/src/lib/number.ts': 'dcbcc98fea337d07e81728c1a6526a1e',
423421
'test-5/src/types/example.d.ts': '76642861732b16754b0110fb1de49823',
424-
'test-5/tsconfig.json': '24a7b8aff2651d9a1920e33459d8c346',
422+
'test-5/tsconfig.json': '5ea2a8356e00e9407dd4641007fd3940',
425423
'test-5/tsconfig.module.json': '2fda4c8760c6cfa3462b40df0645850d',
426424
});
427425
});
@@ -457,7 +455,7 @@ test(`${TestDirectories.six}: Sandboxed: yarn, no initial commit`, async (t) =>
457455
'test-6/.github/ISSUE_TEMPLATE.md': 'e70a0b70402765682b1a961af855040e',
458456
'test-6/.github/PULL_REQUEST_TEMPLATE.md':
459457
'70f4b97f3914e2f399bcc5868e072c29',
460-
'test-6/.gitignore': '2b90e204ba76e30ec95f946ac7c9787e',
458+
'test-6/.gitignore': '703beedaf3cabd7f7fd7d3f57408ec61',
461459
'test-6/.prettierignore': '1da1ce4fdb868f0939608fafd38f9683',
462460
'test-6/.travis.yml': '91976af7b86cffb6960db8c35b27b7d0',
463461
'test-6/.vscode/extensions.json': '2d26a716ba181656faac4cd2d38ec139',
@@ -474,7 +472,7 @@ test(`${TestDirectories.six}: Sandboxed: yarn, no initial commit`, async (t) =>
474472
'test-6/src/lib/number.spec.ts': '0592001d71aa3b3e6bf72f4cd95dc1b9',
475473
'test-6/src/lib/number.ts': 'dcbcc98fea337d07e81728c1a6526a1e',
476474
'test-6/src/types/example.d.ts': '76642861732b16754b0110fb1de49823',
477-
'test-6/tsconfig.json': 'eadf0f5640c5000ceabf242d157861e4',
475+
'test-6/tsconfig.json': '7a9481f033cb07985ee1b903ad42b167',
478476
'test-6/tsconfig.module.json': '2fda4c8760c6cfa3462b40df0645850d',
479477
});
480478
});

‎src/cli/typescript-starter.ts‎

Lines changed: 49 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,23 @@ export async function typescriptStarter(
101101
);
102102

103103
const pkg = readPackageJson(pkgPath);
104+
const removeCliScripts = {
105+
'check-integration-test': undefined,
106+
'check-integration-test:1': undefined,
107+
'check-integration-test:2': undefined,
108+
'check-integration-test:3': undefined,
109+
'check-integration-test:4': undefined,
110+
'check-integration-test:5': undefined,
111+
'check-integration-test:6': undefined,
112+
};
113+
const scripts = {
114+
...pkg.scripts,
115+
...removeCliScripts,
116+
...(runner === Runner.Yarn
117+
? { 'reset-hard': `git clean -dfx && git reset --hard && yarn` }
118+
: {}),
119+
...(cspell ? {} : { 'test:spelling': undefined }),
120+
};
104121
const newPkg = {
105122
...pkg,
106123
dependencies: nodeDefinitions
@@ -111,14 +128,13 @@ export async function typescriptStarter(
111128
keywords: [],
112129
name: projectName,
113130
repository: `https://github.com/${githubUsername}/${projectName}`,
114-
scripts:
115-
runner === Runner.Yarn
116-
? {
117-
...pkg.scripts,
118-
'reset-hard': `git clean -dfx && git reset --hard && yarn`,
119-
}
120-
: { ...pkg.scripts },
131+
scripts,
121132
version: '1.0.0',
133+
ava: {
134+
...pkg.ava,
135+
files: ['!build/module/**'],
136+
ignoredByWatcher: undefined,
137+
},
122138
};
123139

124140
// eslint-disable-next-line functional/immutable-data
@@ -132,6 +148,11 @@ export async function typescriptStarter(
132148
spinnerPackage.succeed();
133149

134150
const spinnerGitignore = ora('Updating .gitignore').start();
151+
await replaceInFile({
152+
files: join(projectPath, '.gitignore'),
153+
from: 'diff\n',
154+
to: '',
155+
});
135156
if (runner === Runner.Yarn) {
136157
await replaceInFile({
137158
files: join(projectPath, '.gitignore'),
@@ -169,6 +190,12 @@ export async function typescriptStarter(
169190
}
170191
if (!circleci) {
171192
del([normalizePath(join(projectPath, '.circleci'))]);
193+
} else {
194+
await replaceInFile({
195+
files: join(projectPath, '.circleci', 'config.yml'),
196+
from: / {6}- run: npm run check-integration-tests\n/g,
197+
to: '',
198+
});
172199
}
173200
if (!cspell) {
174201
del([normalizePath(join(projectPath, '.cspell.json'))]);
@@ -245,6 +272,15 @@ export async function typescriptStarter(
245272
from: '"lib": ["es2017", "dom"]',
246273
to: '"lib": ["es2017"]',
247274
});
275+
await replaceInFile({
276+
files: join(projectPath, 'src', 'index.ts'),
277+
from: `export * from './lib/hash';\n`,
278+
to: '',
279+
});
280+
await del([
281+
normalizePath(join(projectPath, 'src', 'lib', 'hash.ts')),
282+
normalizePath(join(projectPath, 'src', 'lib', 'hash.spec.ts')),
283+
]);
248284
spinnerDom.succeed();
249285
}
250286

@@ -257,7 +293,12 @@ export async function typescriptStarter(
257293
});
258294
await replaceInFile({
259295
files: join(projectPath, 'src', 'index.ts'),
260-
from: /^export[\S\s]*hash';\s*/,
296+
from: `export * from './lib/async';\n`,
297+
to: '',
298+
});
299+
await replaceInFile({
300+
files: join(projectPath, 'src', 'index.ts'),
301+
from: `export * from './lib/hash';\n`,
261302
to: '',
262303
});
263304
await del([

‎tsconfig.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"declaration": true,
1010
"inlineSourceMap": true,
1111
"esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */,
12+
"resolveJsonModule": true /* Include modules imported with .json extension. */,
1213

1314
"strict": true /* Enable all strict type-checking options. */,
1415

0 commit comments

Comments
 (0)