Skip to content

Commit

Permalink
test: add test case.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaywcjlove committed Oct 9, 2021
1 parent 94b8859 commit 11f6385
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 6 deletions.
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@
"prepare": "npm run build",
"watch": "tsbb watch --disable-babel --no-esm",
"build": "tsbb build --disable-babel --no-esm",
"test": "node ./lib/index.js -d test/src -o test/out",
"test:watch": "node ./lib/index.js -d test/src -o test/out --combine test/out/dist.css --watch",
"test:watch2": "node ./lib/index.js -d test/src -o test/out --watch --exclude-css"
"test": "npm run build && tsbb test",
"coverage": "tsbb test --coverage",
"example:test": "node ./lib/index.js -d test/src -o test/out",
"example:test:watch": "node ./lib/index.js -d test/src -o test/out --combine test/out/dist.css --watch",
"example:test:watch2": "node ./lib/index.js -d test/src -o test/out --watch --exclude-css"
},
"repository": {
"type": "git",
Expand Down
6 changes: 3 additions & 3 deletions src/compile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,12 @@ export async function outputFile(data: IOutputFile, inputDir: string, outputDir:
}
}

async function log(output: string, input?: string) {
export async function log(output: string, input?: string) {
const pkg = await readPkgUp();
const projectName = pkg ? pkg?.packageJson.name : '';
if (input) {
console.log(`♻️ \x1b[32m ${projectName}\x1b[0m:`, input, '┈>', output);
console.log(`♻️ \x1b[32m ${projectName}\x1b[0m: ${input} ┈> ${output}`);
} else {
console.log(`♻️ \x1b[32m ${projectName}\x1b[0m:`, 'Output one file: ┈>', output);
console.log(`♻️ \x1b[32m ${projectName}\x1b[0m: Output one file: ┈> ${output}`);
}
}
41 changes: 41 additions & 0 deletions test/compile.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import fs from 'fs-extra';
import compile, { log } from '../src/compile';

it('compile test case', async () => {
await compile('test/src', {
out: 'test/out',
combine: 'test/out/dist.css',
});
const dist = await fs.readFile('test/out/dist.css');
expect(dist.indexOf(':global .a div') > -1).toBeTruthy();
expect(fs.existsSync('test/out/dist.css')).toBeTruthy();
});

it('compile = rmGlobal test case', async () => {
await compile('test/src', {
out: 'test/out',
combine: 'test/out/dist.css',
rmGlobal: true,
});
const dist = await fs.readFile('test/out/dist.css');
expect(dist.indexOf(':global .a div') === -1).toBeTruthy();
});

it('Folder undefined test case', async () => {
console.log = jest.fn();
await compile('test/srcs', {
out: 'test/out',
combine: 'test/out/dist2.css',
});
expect(fs.existsSync('test/out/dist2.css')).toBeFalsy();
// @ts-ignore
expect(console.log.mock.calls[0][0]).toBe(`🚧 \x1b[35mcompile-less-cli\x1b[0m =>\x1b[33m No content is output.\x1b[0m`);
});

it('log test case', async () => {
console.log = jest.fn();
expect(await log('output-path', 'test')).toBeUndefined()
// @ts-ignore
expect(console.log.mock.calls[0][0]).toBe(`♻️ \x1b[32m compile-less-cli\x1b[0m: test ┈> output-path`);
});

0 comments on commit 11f6385

Please sign in to comment.