publication-payload.spec.ts 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. import { describe, expect, it } from 'vitest'
  2. import {
  3. hasTypertRemoteNavigation,
  4. isForbiddenPublicationFile,
  5. validateTarballPayload,
  6. } from './publication-payload.ts'
  7. function validateFixtureTarball(files: readonly string[]): () => void {
  8. return () => {
  9. validateTarballPayload(files, 'fixture.tgz')
  10. }
  11. }
  12. describe('publication payload policy', () => {
  13. it.each([
  14. 'lib/index.js',
  15. 'lib/types/index.d.ts',
  16. 'lib/styles/base.css',
  17. ])('accepts %s', (file) => {
  18. expect(isForbiddenPublicationFile(file)).toBe(false)
  19. })
  20. it.each([
  21. 'src',
  22. './src',
  23. 'src/',
  24. 'src/index.ts',
  25. './src/index.ts',
  26. String.raw`src\index.ts`,
  27. 'lib/types/index.d.ts.map',
  28. './lib/types/index.d.ts.map',
  29. 'lib/typert.remote-client.d.ts.map',
  30. 'lib/client.js.map',
  31. './lib/client.js.map',
  32. ])('rejects static manifest path %s', (file) => {
  33. expect(isForbiddenPublicationFile(file)).toBe(true)
  34. })
  35. it('rejects source members in packed tarballs', () => {
  36. expect(validateFixtureTarball([
  37. 'package/package.json',
  38. 'package/src/index.ts',
  39. ])).toThrow('fixture.tgz publishes source file package/src/index.ts')
  40. })
  41. it('rejects source maps in packed tarballs', () => {
  42. expect(validateFixtureTarball([
  43. 'package/package.json',
  44. 'package/lib/types/index.d.ts.map',
  45. ])).toThrow('fixture.tgz publishes source map package/lib/types/index.d.ts.map')
  46. expect(validateFixtureTarball([
  47. 'package/package.json',
  48. 'package/lib/typert.remote-client.d.ts.map',
  49. ])).toThrow('fixture.tgz publishes source map package/lib/typert.remote-client.d.ts.map')
  50. expect(validateFixtureTarball([
  51. 'package/package.json',
  52. 'package/lib/client.js.map',
  53. ])).toThrow('fixture.tgz publishes source map package/lib/client.js.map')
  54. })
  55. it('accepts a clean packed tarball', () => {
  56. expect(validateFixtureTarball([
  57. 'package/package.json',
  58. 'package/lib/index.js',
  59. 'package/lib/types/index.d.ts',
  60. 'package/lib/styles/base.css',
  61. ])).not.toThrow()
  62. })
  63. it('recognizes only the canonical Host-for-Client export pair', () => {
  64. expect(hasTypertRemoteNavigation({
  65. exports: {
  66. './remote': {
  67. types: './lib/typert.remote-client.d.ts',
  68. default: './lib/typert.remote-client.js',
  69. },
  70. },
  71. })).toBe(true)
  72. expect(hasTypertRemoteNavigation({ exports: { './remote': './lib/remote.js' } })).toBe(false)
  73. })
  74. })