diff --git a/src/run.test.ts b/src/run.test.ts new file mode 100644 index 00000000..2994a694 --- /dev/null +++ b/src/run.test.ts @@ -0,0 +1,16 @@ +import path from 'node:path'; +import fs from 'node:fs'; +import isThere from 'is-there'; +import { rimraf } from 'rimraf'; +import { run } from './run'; + +describe(run, () => { + beforeEach(async () => { + await rimraf('example/style01.css.d.ts'); + }); + + it('generates type definition files', async () => { + await run('example', { watch: false }); + expect(isThere(path.normalize('example/style01.css.d.ts'))).toBeTruthy(); + }); +}); diff --git a/src/run.ts b/src/run.ts index 2856dd2b..44c24225 100644 --- a/src/run.ts +++ b/src/run.ts @@ -17,7 +17,7 @@ interface RunOptions { } export async function run(searchDir: string, options: RunOptions = {}): Promise { - const filesPattern = path.join(searchDir, options.pattern || '**/*.css'); + const filesPattern = searchDir.replace(/\\/g, '/') + '/' + (options.pattern || '**/*.css'); const creator = new DtsCreator({ rootDir: process.cwd(), @@ -78,7 +78,7 @@ export async function run(searchDir: string, options: RunOptions = {}): Promise< } else { console.log('Watch ' + filesPattern + '...'); - const watcher = chokidar.watch([filesPattern.replace(/\\/g, '/')]); + const watcher = chokidar.watch([filesPattern]); watcher.on('add', writeFile); watcher.on('change', writeFile); watcher.on('unlink', deleteFile);