client-tsconfig.spec.ts 1.4 KB

1234567891011121314151617181920212223242526272829303132333435
  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 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. .map(file => file.replaceAll(sep, '/'))
  15. .sort()
  16. }
  17. describe('client TypeScript aggregate', () => {
  18. it('loads package CSS declarations without relying on workspace-link realpaths', () => {
  19. const configPath = resolve(root, 'tsconfig.client.json')
  20. const read = ts.readConfigFile(configPath, file => ts.sys.readFile(file))
  21. if (read.error !== undefined) {
  22. throw new Error(ts.flattenDiagnosticMessageText(read.error.messageText, '\n'))
  23. }
  24. const parsed = ts.parseJsonConfigFileContent(read.config, ts.sys, root)
  25. const loaded = parsed.fileNames
  26. .map(file => file.replaceAll(sep, '/'))
  27. .filter(file => file.endsWith('/src/css-modules.d.ts'))
  28. .sort()
  29. expect(loaded).toEqual(clientCssDeclarations())
  30. })
  31. })