Skip to content

Commit

Permalink
test: fix some test methods failed on windows platform (#3686)
Browse files Browse the repository at this point in the history
  • Loading branch information
qingdengyue authored and atian25 committed May 10, 2019
1 parent 4099902 commit 5b2dbd5
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 10 deletions.
4 changes: 2 additions & 2 deletions test/app/middleware/site_file.test.js
Expand Up @@ -28,7 +28,7 @@ describe('test/app/middleware/site_file.test.js', () => {
it('should 200 when accessing /robots.txt', () => {
return app.httpRequest()
.get('/robots.txt')
.expect('User-agent: Baiduspider\nDisallow: /\n\nUser-agent: baiduspider\nDisallow: /')
.expect(/^User-agent: Baiduspider\r?\nDisallow: \/\r?\n\r?\nUser-agent: baiduspider\r?\nDisallow: \/$/)
.expect(200);
});

Expand All @@ -42,7 +42,7 @@ describe('test/app/middleware/site_file.test.js', () => {
it('should support HEAD', () => {
return app.httpRequest()
.head('/robots.txt')
.expect('content-length', '72')
.expect(res => assert(Number(res.header['content-length']) > 0))
// body must be empty for HEAD
.expect(res => assert.equal(res.text, undefined))
.expect(200);
Expand Down
14 changes: 11 additions & 3 deletions test/lib/core/view.test.js
Expand Up @@ -96,14 +96,19 @@ describe('test/lib/core/view.test.js', () => {
app.httpRequest()
.get('/')
.expect(200)
.expect(`Hi, mk・2\ntest-app-helper: test-bar@${app.config.baseDir}\nraw: <div>dar</div>\n2014 @ mk2 &lt;br&gt;\n`, done);
.expect(res => assert.equal(String(res.text).replace(/\r/g, ''), `Hi, mk・2\ntest-app-helper: test-bar@${app.config.baseDir}\nraw: <div>dar</div>\n2014 @ mk2 &lt;br&gt;\n`))
.end(done)

;
});

it('should render with async function controller', function(done) {
app.httpRequest()
.get('/async')
.expect(200)
.expect(`Hi, mk・2\ntest-app-helper: test-bar@${app.config.baseDir}\nraw: <div>dar</div>\n2014 @ mk2 &lt;br&gt;\n`, done);
.expect(res => assert.equal(String(res.text).replace(/\r/g, ''), `Hi, mk・2\ntest-app-helper: test-bar@${app.config.baseDir}\nraw: <div>dar</div>\n2014 @ mk2 &lt;br&gt;\n`))
.end(done)
;
});

it('should render have helper instance', function(done) {
Expand All @@ -116,7 +121,10 @@ describe('test/lib/core/view.test.js', () => {
app.httpRequest()
.get('/empty')
.expect(200)
.expect(`Hi, \ntest-app-helper: test-bar@${app.config.baseDir}\nraw: <div>dar</div>\n2014 @ mk2 &lt;br&gt;\n`, done);
.expect(res => assert.equal(String(res.text).replace(/\r/g, ''), `Hi, \ntest-app-helper: test-bar@${app.config.baseDir}\nraw: <div>dar</div>\n2014 @ mk2 &lt;br&gt;\n`))

.end(done)
;
});

it('should render template string', function(done) {
Expand Down
5 changes: 2 additions & 3 deletions test/lib/plugins/i18n.test.js
@@ -1,5 +1,4 @@
'use strict';

const utils = require('../../utils');

describe('test/lib/plugins/i18n.test.js', () => {
Expand Down Expand Up @@ -37,7 +36,7 @@ describe('test/lib/plugins/i18n.test.js', () => {
.get('/')
.expect(200)
.expect('Set-Cookie', /locale=en-us; path=\/; expires=[^;]+ GMT/)
.expect('<li>Email: </li>\n<li>Hello fengmk2, how are you today?</li>\n<li>foo bar</li>\n');
.expect(/^<li>Email: <\/li>\r?\n<li>Hello fengmk2, how are you today\?<\/li>\r?\n<li>foo bar<\/li>\r?\n$/);
});

it('should render with query locale: zh_CN', () => {
Expand All @@ -46,7 +45,7 @@ describe('test/lib/plugins/i18n.test.js', () => {
.set('Host', 'foo.example.com')
.expect(200)
.expect('Set-Cookie', /locale=zh-cn; path=\/; expires=[^;]+ GMT/)
.expect('<li>邮箱: </li>\n<li>fengmk2,今天过得如何?</li>\n<li>foo bar</li>\n');
.expect(/^<li>邮箱: <\/li>\r?\n<li>fengmk2,今天过得如何?<\/li>\r?\n<li>foo bar<\/li>\r?\n$/);
});
});
});
3 changes: 1 addition & 2 deletions test/lib/plugins/static.test.js
@@ -1,5 +1,4 @@
'use strict';

const utils = require('../../utils');

describe('test/lib/plugins/static.test.js', () => {
Expand All @@ -12,7 +11,7 @@ describe('test/lib/plugins/static.test.js', () => {
it('should get exists js file', () => {
return app.httpRequest()
.get('/public/foo.js')
.expect('alert(\'bar\');\n')
.expect(/alert\(\'bar\'\);\r?\n/)
.expect(200);
});
});

0 comments on commit 5b2dbd5

Please sign in to comment.