|
| 1 | +import test, { TestContext } from 'ava'; |
| 2 | +import { readFileSync } from 'fs'; |
| 3 | +const path = require('path'); |
| 4 | +import * as postcss from 'postcss'; |
| 5 | + |
| 6 | +import { PostcssTypescriptCss } from '../namespace/PostcssTypescriptCss'; |
| 7 | +import * as plugin from '../postcss-typescript-css'; |
| 8 | + |
| 9 | +function run(t: TestContext, input: {css: string, from: string}) { |
| 10 | + return postcss([ plugin ]).process(input.css, { from: input.from }) |
| 11 | + .then((result) => { |
| 12 | + const fakeComponentTS = readFileSync(path.join(__dirname, 'postcss/fakeComponent.ts'), 'utf8'); |
| 13 | + t.true(fakeComponentTS.includes('fakeComponentStyle')); |
| 14 | + t.true(fakeComponentTS.includes('fakeComponent:')); |
| 15 | + t.true(fakeComponentTS.includes('fakeComponentDescendentName:')); |
| 16 | + t.true(fakeComponentTS.includes('fakeComponentModifierName:')); |
| 17 | + }) |
| 18 | + .catch((err: string) => { |
| 19 | + t.true(err.includes('TypeError: Path must be a string')); |
| 20 | + }); |
| 21 | +} |
| 22 | + |
| 23 | +test('should create a ts file', t => { |
| 24 | + const cssFile = path.join(__dirname, 'postcss/fakeComponent.postcss'); |
| 25 | + const cssContent = readFileSync(cssFile, 'utf8'); |
| 26 | + return run(t, { css: cssContent, from: cssFile }); |
| 27 | +}); |
| 28 | + |
| 29 | +test('throws if cssFileName is null', t => { |
| 30 | + return run(t, { css: '', from: '' }); |
| 31 | +}); |
0 commit comments