client-tsconfig.spec.ts 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. /** Regression coverage for source declarations owned by the client test aggregate. */
  2. import { existsSync, readdirSync } from 'node:fs'
  3. import { resolve, sep } 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 clientGroups = ['client', 'extensions']
  10. return clientGroups.flatMap((group) => {
  11. const clientRoot = resolve(root, 'packages', group)
  12. return readdirSync(clientRoot, { withFileTypes: true })
  13. .filter(entry => entry.isDirectory())
  14. .map(entry => resolve(clientRoot, entry.name, 'src/css-modules.d.ts'))
  15. })
  16. .filter(existsSync)
  17. .map(file => file.replaceAll(sep, '/'))
  18. .sort()
  19. }
  20. describe('client TypeScript aggregate', () => {
  21. it('loads package CSS declarations without relying on workspace-link realpaths', () => {
  22. const configPath = resolve(root, 'tsconfig.client.json')
  23. const read = ts.readConfigFile(configPath, file => ts.sys.readFile(file))
  24. if (read.error !== undefined) {
  25. throw new Error(ts.flattenDiagnosticMessageText(read.error.messageText, '\n'))
  26. }
  27. const parsed = ts.parseJsonConfigFileContent(read.config, ts.sys, root)
  28. const loaded = parsed.fileNames
  29. .map(file => file.replaceAll(sep, '/'))
  30. .filter(file => file.endsWith('/src/css-modules.d.ts'))
  31. .sort()
  32. expect(loaded).toEqual(clientCssDeclarations())
  33. })
  34. })