Skip to content

Commit e8f650c

Browse files
committed
Make tests work with repotools
1 parent d638ed0 commit e8f650c

File tree

55 files changed

+97
-57
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+97
-57
lines changed

lib/buildtools/src/testing/utils.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,10 @@ export async function getTestConfiguration(directory: string, watch: boolean): P
109109

110110
const packageJsonResult = await findPackageJson(directory);
111111
if (packageJsonResult === null) {
112-
throw new Error(`Could not find a package.json for ${directory}`);
112+
return {
113+
severity: 'success',
114+
config: null
115+
};
113116
}
114117

115118
const [type, jsonDir] = packageJsonResult;

lib/repotools/package.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
"description": "Common library for tooling used by the modules repository",
77
"devDependencies": {
88
"@commander-js/extra-typings": "^13.0.0",
9-
"typescript": "^5.8.2"
9+
"typescript": "^5.8.2",
10+
"vitest": "^3.2.3"
1011
},
1112
"dependencies": {
1213
"chalk": "^5.0.1",
@@ -19,6 +20,9 @@
1920
"./*": "./dist/*.js"
2021
},
2122
"scripts": {
22-
"build": "tsc"
23+
"build": "tsc --project ./tsconfig.prod.json",
24+
"prepare": "yarn build",
25+
"tsc": "tsc --project ./tsconfig.json",
26+
"test": "vitest"
2327
}
2428
}

lib/repotools/src/__tests__/manifest.test.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
1+
import pathlib from 'path';
12
import { describe, expect, it, test, vi } from 'vitest';
2-
import { expectIsSuccess, testMocksDir } from '../../../buildtools/src/__tests__/fixtures.js';
33
import { resolveAllTabs, resolveSingleTab } from '../manifest.js';
44

5+
const testMocksDir = pathlib.resolve(import.meta.dirname, '../../../__test_mocks__');
56
vi.mock(import('../getGitRoot.js'));
67

8+
function expectSuccess(obj: unknown): asserts obj is 'success' {
9+
expect(obj).toEqual('success');
10+
}
11+
712
describe('Test resolveSingleTab', () => {
813
it('properly detects a tab with the src/index.tsx entrypoint', async () => {
914
const resolved = await resolveSingleTab(`${testMocksDir}/tabs/tab0`);
@@ -30,8 +35,8 @@ describe('Test resolveSingleTab', () => {
3035

3136
test('resolveAllTabs', async () => {
3237
const resolved = await resolveAllTabs(`${testMocksDir}/bundles`, `${testMocksDir}/tabs`);
38+
expectSuccess(resolved.severity);
3339

34-
expectIsSuccess(resolved.severity);
3540
const { tabs } = resolved;
3641

3742
expect(tabs).toHaveProperty('tab0');

lib/repotools/tsconfig.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1+
// Repotools regular tsconfig
12
{
23
"extends": ["../tsconfig.json"],
34
"include": ["./src"],
45
"compilerOptions": {
5-
"declaration": true,
66
"module": "nodenext",
7-
"moduleResolution": "nodenext",
8-
"noEmit": false,
9-
"outDir": "./dist"
7+
"moduleResolution": "nodenext"
108
}
119
}

lib/repotools/tsconfig.prod.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Repotools production tsconfig
2+
{
3+
"extends": ["./tsconfig.json"],
4+
"include": ["./src"],
5+
"exclude": ["**/__tests__/**", "**/__mocks__/**"],
6+
"compilerOptions": {
7+
"declaration": true,
8+
"noEmit": false,
9+
"outDir": "./dist"
10+
}
11+
}

lib/repotools/vitest.config.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// @ts-check
2+
import rootConfig from '../../vitest.config.js';
3+
4+
/**
5+
* @type {import('vitest/config').ViteUserConfig}
6+
*/
7+
const config = {
8+
test: {
9+
...rootConfig.test,
10+
name: 'Repo Tools',
11+
root: import.meta.dirname,
12+
include: ['**/__tests__/*.test.ts'],
13+
watch: false,
14+
projects: []
15+
}
16+
};
17+
18+
export default config;

src/bundles/ar/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,4 @@
2121
"tsc": "buildtools tsc .",
2222
"test": "buildtools test --project ."
2323
}
24-
}
24+
}

src/bundles/arcade_2d/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,4 @@
2121
"tsc": "buildtools tsc .",
2222
"test": "buildtools test --project ."
2323
}
24-
}
24+
}

src/bundles/binary_tree/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@
1717
"lint": "buildtools lint .",
1818
"test": "buildtools test --project ."
1919
}
20-
}
20+
}

src/bundles/communication/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,4 @@
2222
"tsc": "buildtools tsc .",
2323
"lint": "buildtools lint ."
2424
}
25-
}
25+
}

0 commit comments

Comments
 (0)