|
3 | 3 | import * as path from 'path'; |
4 | 4 |
|
5 | 5 | import * as assert from 'assert'; |
6 | | -import * as os from 'os'; |
7 | 6 | import { DtsCreator } from '../src/dts-creator'; |
| 7 | +import SpyInstance = jest.SpyInstance; |
8 | 8 |
|
9 | 9 | describe('DtsCreator', () => { |
10 | 10 | var creator = new DtsCreator(); |
@@ -91,6 +91,15 @@ describe('DtsContent', () => { |
91 | 91 | }); |
92 | 92 | }); |
93 | 93 |
|
| 94 | + describe('#relativeInputFilePath', () => { |
| 95 | + it('returns relative original CSS file name', done => { |
| 96 | + new DtsCreator().create(path.normalize('test/testStyle.css')).then(content => { |
| 97 | + assert.equal(content.relativeInputFilePath, 'test/testStyle.css'); |
| 98 | + done(); |
| 99 | + }); |
| 100 | + }); |
| 101 | + }); |
| 102 | + |
94 | 103 | describe('#outputFilePath', () => { |
95 | 104 | it('adds d.ts to the original filename', done => { |
96 | 105 | new DtsCreator().create(path.normalize('test/testStyle.css')).then(content => { |
@@ -210,6 +219,66 @@ export = styles; |
210 | 219 | }); |
211 | 220 | }); |
212 | 221 |
|
| 222 | + describe('#checkFile', () => { |
| 223 | + let mockExit: SpyInstance; |
| 224 | + let mockConsoleLog: SpyInstance; |
| 225 | + let mockConsoleError: SpyInstance; |
| 226 | + |
| 227 | + beforeAll(() => { |
| 228 | + mockExit = jest.spyOn(process, 'exit').mockImplementation(exitCode => { |
| 229 | + throw new Error(`process.exit: ${exitCode}`); |
| 230 | + }); |
| 231 | + mockConsoleLog = jest.spyOn(console, 'log').mockImplementation(); |
| 232 | + mockConsoleError = jest.spyOn(console, 'error').mockImplementation(); |
| 233 | + }); |
| 234 | + |
| 235 | + beforeEach(() => { |
| 236 | + jest.clearAllMocks(); |
| 237 | + }); |
| 238 | + |
| 239 | + afterAll(() => { |
| 240 | + mockExit.mockRestore(); |
| 241 | + mockConsoleLog.mockRestore(); |
| 242 | + mockConsoleError.mockRestore(); |
| 243 | + }); |
| 244 | + |
| 245 | + it('return false if type file is missing', done => { |
| 246 | + new DtsCreator() |
| 247 | + .create('test/empty.css') |
| 248 | + .then(content => { |
| 249 | + return content.checkFile(); |
| 250 | + }) |
| 251 | + .then(result => { |
| 252 | + assert.equal(result, false); |
| 253 | + done(); |
| 254 | + }); |
| 255 | + }); |
| 256 | + |
| 257 | + it('returns false if type file content is different', done => { |
| 258 | + new DtsCreator() |
| 259 | + .create('test/different.css') |
| 260 | + .then(content => { |
| 261 | + return content.checkFile(); |
| 262 | + }) |
| 263 | + .then(result => { |
| 264 | + assert.equal(result, false); |
| 265 | + done(); |
| 266 | + }); |
| 267 | + }); |
| 268 | + |
| 269 | + it('returns true if type files match', done => { |
| 270 | + new DtsCreator() |
| 271 | + .create('test/testStyle.css') |
| 272 | + .then(content => { |
| 273 | + return content.checkFile(); |
| 274 | + }) |
| 275 | + .then(result => { |
| 276 | + assert.equal(result, true); |
| 277 | + done(); |
| 278 | + }); |
| 279 | + }); |
| 280 | + }); |
| 281 | + |
213 | 282 | describe('#writeFile', () => { |
214 | 283 | it('accepts a postprocessor function', done => { |
215 | 284 | new DtsCreator() |
|
0 commit comments