Skip to content

Commit

Permalink
update tc
Browse files Browse the repository at this point in the history
  • Loading branch information
yiminghe committed Aug 1, 2019
1 parent bea6fd3 commit 9c08757
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 34 deletions.
4 changes: 1 addition & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,4 @@ node_js:
- 10.15.0

script:
- npm test
- npm run-script cover
- cat ./coverage/lcov.info | node ./node_modules/coveralls/bin/coveralls
- npm run coverage
File renamed without changes.
File renamed without changes.
58 changes: 36 additions & 22 deletions tests/specs/index.js → __tests__/specs/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
var xtpl = require('../../');
var path = require('path');
var xtplKoa = require('../../lib/koa2');
var expect = require('expect.js');
var request = require('supertest');
var Koa=require('koa');

Expand All @@ -14,47 +13,50 @@ function normalizeSlash(path) {

describe('xtpl', function () {
it('can get XTemplate engine', function () {
expect(xtpl.XTemplate).not.to.be(undefined);
expect(xtpl.XTemplate).not.toBe(undefined);
});

it('works on node', function (done) {
xtpl.renderFile(path.resolve(__dirname, '../fixture/main.xtpl'), {
y: '<',
x: '>'
}, function (err, data) {
expect(err).to.be(null);
expect(data).to.be('<&gt;');
expect(err).toBe(null);
expect(data).toBe('<&gt;');
console.log('oooo')
done();
});
});

it('works on node when cached', function (done) {
function check(){
if (++count === 2) {
console.log('check');
done();
}
}
var tplPath = normalizeSlash(path.resolve(__dirname, '../fixture/main.xtpl'));
var count = 0;
expect(xtpl.getCache(tplPath).instance).not.to.be.ok();
expect(!!xtpl.getCache(tplPath).instance).toBe(false);
xtpl.renderFile(tplPath, {
y: '<',
x: '>',
cache: 1
}, function (err, data) {
expect(err).to.be(null);
expect(data).to.be('<&gt;');
if (++count === 2) {
done();
}
expect(err).toBe(null);
expect(data).toBe('<&gt;');
check();
});
//console.log(xtpl.getCaches());
expect(xtpl.getCache(tplPath).instance.config.name).to.be(tplPath);
expect(xtpl.getCache(tplPath).instance.config.name).toBe(tplPath);
xtpl.renderFile(tplPath, {
y: '<',
x: '>',
cache: 1
}, function (err, data) {
expect(err).to.be(null);
expect(data).to.be('<&gt;');
if (++count === 2) {
done();
}
expect(err).toBe(null);
expect(data).toBe('<&gt;');
check();
});
});

Expand All @@ -73,12 +75,18 @@ describe('xtpl', function () {
x: '>',
age: 20
});
expect(html).to.be('<&gt;foo20');
expect(html).toBe('<&gt;foo20');
});
request(app.listen())

const server = app.listen();
request(server)
.get('/')
.expect(200)
.expect('<&gt;foo20', done);
.expect('<&gt;foo20', ()=>{
console.log('oooo')
server.close();
done();
});
});

it('works for koa and absolute path', function (done) {
Expand All @@ -92,11 +100,17 @@ describe('xtpl', function () {
x: '>',
age: 20
});
expect(html).to.be('<&gt;foo20');
expect(html).toBe('<&gt;foo20');
});
request(app.listen())
const server = app.listen();
request(server)
.get('/')
.expect(200)
.expect('<&gt;foo20', done);
.expect('<&gt;foo20', ()=>{
console.log('oooo')
server.close();
done();
});

});
});
14 changes: 5 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
"node": ">=0.10"
},
"scripts": {
"pub":"git push && npm publish",
"test": "node --harmony ./node_modules/mocha/bin/mocha --harmony -R list tests/specs",
"cover": "node --harmony ./node_modules/istanbul/lib/cli cover ./node_modules/mocha/bin/_mocha -- -R list tests/specs/"
"pub": "git push && npm publish",
"test": "jest",
"coverage": "jest --coverage && cat ./coverage/lcov.info | coveralls"
},
"repository": {
"type": "git",
Expand All @@ -33,14 +33,10 @@
},
"devDependencies": {
"coveralls": "~2.11.9",
"expect.js": "^0.3.1",
"express": "~3.4.8",
"istanbul": "~0.4.3",
"jest": "^24.8.0",
"koa": "^2.7.0",
"mocha": "~2.5.3",
"mocha-istanbul": "~0.2.0",
"request": "^2.72.0",
"supertest": "~1.2.0",
"supertest": "4.x",
"xtemplate": "5.x"
}
}

0 comments on commit 9c08757

Please sign in to comment.