client-tsconfig.spec.ts 1.3 KB

123456789101112131415161718192021222324252627282930313233
  1. /** Regression coverage for source declarations owned by the client test aggregate. */
  2. import { existsSync, readdirSync } from 'node:fs'
  3. import { resolve } from 'node:path'
  4. import { fileURLToPath } from 'node:url'
  5. import ts from 'typescript'
  6. import { describe, expect, it } from 'vitest'
  7. const root = fileURLToPath(new URL('..', import.meta.url))
  8. function clientCssDeclarations(): string[] {
  9. const clientRoot = resolve(root, 'packages/client')
  10. return readdirSync(clientRoot, { withFileTypes: true })
  11. .filter(entry => entry.isDirectory())
  12. .map(entry => resolve(clientRoot, entry.name, 'src/css-modules.d.ts'))
  13. .filter(existsSync)
  14. .sort()
  15. }
  16. describe('client TypeScript aggregate', () => {
  17. it('loads package CSS declarations without relying on workspace-link realpaths', () => {
  18. const configPath = resolve(root, 'tsconfig.client.json')
  19. const read = ts.readConfigFile(configPath, file => ts.sys.readFile(file))
  20. if (read.error !== undefined) {
  21. throw new Error(ts.flattenDiagnosticMessageText(read.error.messageText, '\n'))
  22. }
  23. const parsed = ts.parseJsonConfigFileContent(read.config, ts.sys, root)
  24. const loaded = parsed.fileNames
  25. .filter(file => file.endsWith('/src/css-modules.d.ts'))
  26. .sort()
  27. expect(loaded).toEqual(clientCssDeclarations())
  28. })
  29. })