1 |
|
2 | var fs = require('fs')
|
3 | var path = require('path')
|
4 | var Reporter = require('jasmine-spec-reporter')
|
5 | var Converter = require(path.resolve(__dirname, '../lib'))
|
6 |
|
7 |
|
8 | var reporter = new Reporter({
|
9 | displayStacktrace: 'none',
|
10 | displaySuccessesSummary: true,
|
11 | displayFailuresSummary: false,
|
12 | displaySuccessfulSpec: true,
|
13 | displayFailedSpec: true
|
14 | })
|
15 |
|
16 | jasmine.getEnv().clearReporters()
|
17 | jasmine.getEnv().addReporter(reporter);
|
18 |
|
19 | describe('SCSS to LESS converter', function() {
|
20 | let fixtures, converter
|
21 |
|
22 | function getName(file) {
|
23 | return file.split('.')[0]
|
24 | }
|
25 |
|
26 | function runTest(name, fixtureFile, expectedFile) {
|
27 | let convert = new Promise(function(resolve, reject) {
|
28 | fs.readFile(fixtureFile, 'utf-8', function(err, data) {
|
29 | if (err) reject(err);
|
30 | resolve(converter.process(data, { fileInfo: { filename: fixtureFile } }))
|
31 | })
|
32 | })
|
33 |
|
34 | let expected = new Promise(function(resolve, reject) {
|
35 | fs.readFile(expectedFile, 'utf-8', function(err, data) {
|
36 | if (err) reject(err);
|
37 | resolve(data);
|
38 | })
|
39 | })
|
40 |
|
41 | it('should convert "' + name + '"', function (done) {
|
42 | var test = function(values) {
|
43 | expect(values[0]).toEqual(values[1])
|
44 | done()
|
45 | }
|
46 |
|
47 | var error = function(err) {
|
48 | fail(err)
|
49 | }
|
50 |
|
51 | Promise.all([convert, expected]).then(test).catch(error)
|
52 | })
|
53 | }
|
54 |
|
55 |
|
56 | fixtures = fs.readdirSync(path.resolve(__dirname, './fixtures'))
|
57 |
|
58 |
|
59 | converter = new Converter()
|
60 |
|
61 | fixtures.map(function (file) {
|
62 | let filename = getName(file)
|
63 | runTest(filename, path.resolve(__dirname, './fixtures', file), path.resolve(__dirname, './expected', filename + '.less'))
|
64 | })
|
65 | })
|