-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8f77eca
commit 8d812b3
Showing
6 changed files
with
153 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { BUILD_OPTIONS, exists } from '../shared/test-utils.js'; | ||
import { describe, expect, it } from 'vitest'; | ||
import { Builder } from './builder.js'; | ||
import path from 'node:path'; | ||
|
||
describe('building', () => { | ||
it('should empty the out directory', async () => { | ||
const builder = new Builder(BUILD_OPTIONS); | ||
await builder.emptyOutDirectory(); | ||
|
||
expect(await exists(BUILD_OPTIONS.outDirectory)).toBe(false); | ||
}); | ||
|
||
it('should get folders and files', async () => { | ||
const builder = new Builder(BUILD_OPTIONS); | ||
const [folders, files] = await builder.getFoldersAndFiles(); | ||
|
||
expect(folders).toContain('src'); | ||
expect(files).toContain('src/index.js'); | ||
}); | ||
|
||
it('should create the folder structure', async () => { | ||
const builder = new Builder(BUILD_OPTIONS); | ||
await builder.createFolderStructure(['test']); | ||
|
||
expect( | ||
await exists(path.join(BUILD_OPTIONS.outDirectory, 'test')) | ||
).toBe(true); | ||
}); | ||
|
||
it('should copy files', async () => { | ||
const builder = new Builder(BUILD_OPTIONS); | ||
await builder.copyFiles(['./README.md', './src/index.js']); | ||
|
||
expect( | ||
await exists(path.join(BUILD_OPTIONS.outDirectory, 'README.md')) | ||
).toBe(true); | ||
expect( | ||
await exists(path.join(BUILD_OPTIONS.outDirectory, 'src/index.js')) | ||
).toBe(true); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { describe, expect, it } from 'vitest'; | ||
import { BUILD_OPTIONS } from '../shared/test-utils.js'; | ||
import { Bundler } from './bundler.js'; | ||
|
||
describe('bundling', () => { | ||
it('should get entry points', async () => { | ||
const bundler = new Bundler(BUILD_OPTIONS); | ||
const entryPoints = await bundler.getEntryPoints(['./README.md']); | ||
|
||
expect(entryPoints.length).toBe(0); | ||
}); | ||
|
||
it('should bundle', async () => { | ||
const bundler = new Bundler(BUILD_OPTIONS); | ||
await bundler.bundle([]); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { describe, expect, it } from 'vitest'; | ||
import { isLocal, resolvePath } from './utils.js'; | ||
|
||
describe('local paths', () => { | ||
it('should return true on absolute local path', () => { | ||
expect(isLocal('/')).toBe(true); | ||
}); | ||
|
||
it('should return true on relative local path', () => { | ||
expect(isLocal('./')).toBe(true); | ||
expect(isLocal('../')).toBe(true); | ||
}); | ||
|
||
it('should return false on //', () => { | ||
expect(isLocal('//')).toBe(false); | ||
}); | ||
|
||
it('should return false on http://', () => { | ||
expect(isLocal('http://')).toBe(false); | ||
}); | ||
|
||
it('should return false on https://', () => { | ||
expect(isLocal('https://')).toBe(false); | ||
}); | ||
|
||
it('should return false on nonsense', () => { | ||
expect(isLocal(0)).toBe(false); | ||
}); | ||
}); | ||
|
||
describe('path resolving', () => { | ||
const ROOT = 'root'; | ||
|
||
it('should resolve absolute path', () => { | ||
expect( | ||
resolvePath(ROOT, `${ROOT}/test1/test2`, '/test3') | ||
).toBe(`${ROOT}/test3`); | ||
}); | ||
|
||
it('should resolve relative path', () => { | ||
expect( | ||
resolvePath(ROOT, `${ROOT}/test1/test2`, './test3') | ||
).toBe(`${ROOT}/test1/test3`); | ||
expect( | ||
resolvePath(ROOT, `${ROOT}/test1/test2/`, './test3') | ||
).toBe(`${ROOT}/test1/test2/test3`); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { describe, expect, it, vi } from 'vitest'; | ||
import { readFile, unlink } from 'node:fs/promises'; | ||
import { BUILD_OPTIONS } from '../shared/test-utils.js'; | ||
import { Cleaner } from './cleaner.js'; | ||
|
||
vi.mock('node:fs/promises', () => ({ | ||
readFile: vi.fn(() => Promise.resolve(Buffer.from(''))), | ||
unlink: vi.fn(() => Promise.resolve()) | ||
})); | ||
|
||
describe('cleaning', () => { | ||
it('should clean up', async () => { | ||
const cleaner = new Cleaner(BUILD_OPTIONS); | ||
await cleaner.cleanUp(['./README.md', './src/index.js']); | ||
|
||
expect(readFile).toHaveBeenCalled(); | ||
expect(unlink).toHaveBeenCalled(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { DEFAULT_BUILD_OPTIONS } from '../../index.js'; | ||
import { stat } from 'node:fs/promises'; | ||
|
||
/** @type {FullBuildOptions} */ | ||
export const BUILD_OPTIONS = { | ||
...DEFAULT_BUILD_OPTIONS, | ||
directories: ['src'], | ||
ignoreList: ['.test.js'], | ||
outDirectory: 'out', | ||
rootDirectory: 'src' | ||
}; | ||
|
||
/** | ||
* @param {string} path | ||
* @returns {Promise<boolean>} | ||
*/ | ||
export async function exists(path) { | ||
try { | ||
await stat(path); | ||
return true; | ||
} catch { | ||
return false; | ||
} | ||
} |