|
4 | 4 | */ |
5 | 5 |
|
6 | 6 | const assert = require('assert'); |
| 7 | +const fs = require('fs'); |
| 8 | +const path = require('path'); |
| 9 | +const {ts2php} = require('../dist/index.js'); |
7 | 10 |
|
8 | | -describe('Array', function () { |
9 | | - describe('#indexOf()', function () { |
10 | | - it('should return -1 when the value is not present', function () { |
11 | | - assert.equal([1, 2, 3].indexOf(4), -1); |
| 11 | +const files = fs.readdirSync(path.resolve(__dirname, './features')); |
| 12 | +const featureNames = files.reduce((res, file) => { |
| 13 | + const m = file.match(/(.+)\.ts/); |
| 14 | + if (m) { |
| 15 | + res.push(m[1]); |
| 16 | + } |
| 17 | + return res; |
| 18 | +}, []); |
| 19 | + |
| 20 | +function readFile(path) { |
| 21 | + return new Promise((resolve, reject) => { |
| 22 | + fs.readFile(path, {encoding: 'utf-8'}, (err, data) => { |
| 23 | + resolve(data); |
12 | 24 | }); |
13 | 25 | }); |
| 26 | +} |
| 27 | + |
| 28 | + |
| 29 | + |
| 30 | +describe('features', () => { |
| 31 | + for (let i = 0; i < featureNames.length; i++) { |
| 32 | + it('template', async () => { |
| 33 | + const featureName = featureNames[i]; |
| 34 | + const phpContent = await readFile(path.resolve(__dirname, `./features/${featureName}.php`)); |
| 35 | + const tsPath = path.resolve(__dirname, `./features/${featureName}.ts`); |
| 36 | + const res = ts2php(tsPath, { |
| 37 | + modules: { |
| 38 | + './atomWiseUtils': { |
| 39 | + path: './path/to/utils.php', |
| 40 | + className: 'Atom_Wise_Utils' |
| 41 | + }, |
| 42 | + './tplData': { |
| 43 | + path: '', |
| 44 | + className: '' |
| 45 | + } |
| 46 | + } |
| 47 | + }); |
| 48 | + fs.writeFileSync(path.resolve(__dirname, '../output/' + featureName + '.php'), res.phpCode); |
| 49 | + assert.equal(res.phpCode, phpContent); |
| 50 | + }); |
| 51 | + } |
14 | 52 | }); |
| 53 | + |
0 commit comments