|
|
import { existsSync } from 'fs'; |
|
|
import { describe, it, expect } from 'vitest'; |
|
|
import { globSync } from 'glob'; |
|
|
|
|
|
import packageJson from '../package.json'; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
describe('expected folder structure', () => { |
|
|
describe('package.json', () => { |
|
|
it('should include output files', () => { |
|
|
expect(packageJson.files).toHaveLength(5); |
|
|
expect(packageJson.files).toContain('*.md'); |
|
|
expect(packageJson.files).toContain('types'); |
|
|
expect(packageJson.files).toContain('es6'); |
|
|
expect(packageJson.files).toContain('umd'); |
|
|
expect(packageJson.files).toContain('lib'); |
|
|
}); |
|
|
|
|
|
it('should point to a main file', () => { |
|
|
expect(packageJson.main).toEqual('lib/index.js'); |
|
|
expect(existsSync(`./${packageJson.main}`)).toBe(true); |
|
|
}); |
|
|
|
|
|
it('should point to a main module file', () => { |
|
|
expect(packageJson.module).toEqual('es6/index.js'); |
|
|
expect(existsSync(`./${packageJson.module}`)).toBe(true); |
|
|
}); |
|
|
|
|
|
it('should point to a jsnext:main file', () => { |
|
|
expect(packageJson['jsnext:main']).toEqual('es6/index.js'); |
|
|
expect(existsSync(`./${packageJson['jsnext:main']}`)).toBe(true); |
|
|
}); |
|
|
|
|
|
it('should point to a types file', () => { |
|
|
expect(packageJson.types).toEqual('types/index.d.ts'); |
|
|
expect(existsSync(`./${packageJson.types}`)).toBe(true); |
|
|
}); |
|
|
}); |
|
|
|
|
|
async function checkFolderOutput(folder: string, snapshot: string) { |
|
|
return expect(globSync(folder, { dot: true, platform: 'linux' }).sort()).toMatchFileSnapshot( |
|
|
`./snapshots/${snapshot}.txt`, |
|
|
); |
|
|
} |
|
|
|
|
|
describe('types folder output', () => { |
|
|
it('should have expected files and no more', async () => { |
|
|
await checkFolderOutput('types/**/*', 'typesFiles'); |
|
|
}); |
|
|
}); |
|
|
|
|
|
describe('es6 folder output', () => { |
|
|
it('should have expected files and no more', async () => { |
|
|
await checkFolderOutput('es6/**/*', 'es6Files'); |
|
|
}); |
|
|
}); |
|
|
|
|
|
describe('markdown files output', () => { |
|
|
it('should have expected files and no more', async () => { |
|
|
await checkFolderOutput('*.md', 'markdownFiles'); |
|
|
}); |
|
|
}); |
|
|
|
|
|
describe('umd folder output', () => { |
|
|
it('should have expected files and no more', async () => { |
|
|
await checkFolderOutput('umd/**/*', 'umdFiles'); |
|
|
}); |
|
|
}); |
|
|
|
|
|
describe('lib folder output', () => { |
|
|
it('should have expected files and no more', async () => { |
|
|
await checkFolderOutput('lib/**/*', 'libFiles'); |
|
|
}); |
|
|
}); |
|
|
}); |
|
|
|