commit
a796c66b6c
|
@ -1,11 +1,8 @@
|
||||||
sudo: false
|
sudo: false
|
||||||
language: node_js
|
language: node_js
|
||||||
node_js:
|
node_js:
|
||||||
|
- '5'
|
||||||
- '4'
|
- '4'
|
||||||
- '3'
|
|
||||||
- '2'
|
|
||||||
- '1'
|
|
||||||
- '0.12'
|
|
||||||
script:
|
script:
|
||||||
- 'npm run test-cov'
|
- 'npm run test-cov'
|
||||||
after_script:
|
after_script:
|
||||||
|
|
3
index.js
3
index.js
|
@ -177,7 +177,8 @@ module.exports = function (app, options) {
|
||||||
locale = defaultLocale;
|
locale = defaultLocale;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cookieLocale !== locale) {
|
// if header not send, set the locale cookie
|
||||||
|
if (cookieLocale !== locale && !this.headerSent) {
|
||||||
// locale change, need to set cookie
|
// locale change, need to set cookie
|
||||||
this.cookies.set(cookieField, locale, {
|
this.cookies.set(cookieField, locale, {
|
||||||
// make sure brower javascript can read the cookie
|
// make sure brower javascript can read the cookie
|
||||||
|
|
|
@ -7,11 +7,10 @@
|
||||||
"index.js"
|
"index.js"
|
||||||
],
|
],
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "eslint . && mocha --harmony --check-leaks -R spec -t 5000 test/*.test.js",
|
"test": "eslint . && mocha --check-leaks -R spec -t 5000 test/*.test.js",
|
||||||
"test-cov": "node --harmony node_modules/.bin/istanbul cover node_modules/.bin/_mocha -- --check-leaks -t 5000 test/*.test.js",
|
"test-cov": "istanbul cover _mocha -- --check-leaks -t 5000 test/*.test.js",
|
||||||
"lint": "eslint .",
|
"lint": "eslint .",
|
||||||
"autod": "autod -w --prefix '~'",
|
"autod": "autod -w --prefix '~'",
|
||||||
"cnpm": "npm install --registry=https://registry.npm.taobao.org",
|
|
||||||
"contributors": "contributors -f plain -o AUTHORS"
|
"contributors": "contributors -f plain -o AUTHORS"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
@ -25,8 +24,8 @@
|
||||||
"beautify-benchmark": "0",
|
"beautify-benchmark": "0",
|
||||||
"benchmark": "1",
|
"benchmark": "1",
|
||||||
"contributors": "*",
|
"contributors": "*",
|
||||||
"eslint": "~1.5.0",
|
"eslint": "1",
|
||||||
"istanbul-harmony": "*",
|
"istanbul": "*",
|
||||||
"koa": "1",
|
"koa": "1",
|
||||||
"mm": "1",
|
"mm": "1",
|
||||||
"mocha": "*",
|
"mocha": "*",
|
||||||
|
|
|
@ -1,6 +1,4 @@
|
||||||
/**!
|
/**
|
||||||
* koa-locales - test/index.test.js
|
|
||||||
*
|
|
||||||
* Copyright(c) koajs and other contributors.
|
* Copyright(c) koajs and other contributors.
|
||||||
* MIT Licensed
|
* MIT Licensed
|
||||||
*
|
*
|
||||||
|
@ -51,6 +49,16 @@ describe('koa-locales.test.js', function () {
|
||||||
.expect('Set-Cookie', /^locale=en\-us; path=\/; expires=\w+/)
|
.expect('Set-Cookie', /^locale=en\-us; path=\/; expires=\w+/)
|
||||||
.expect(200, done);
|
.expect(200, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should not set locale cookie after header sent', function(done) {
|
||||||
|
request(app.callback())
|
||||||
|
.get('/headerSent')
|
||||||
|
.expect('foo')
|
||||||
|
.expect(200, function(err) {
|
||||||
|
assert(!err, err && err.message);
|
||||||
|
setTimeout(done, 50);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('custom options', function () {
|
describe('custom options', function () {
|
||||||
|
@ -397,6 +405,15 @@ function createApp(options) {
|
||||||
const fname = options && options.functionName || '__';
|
const fname = options && options.functionName || '__';
|
||||||
|
|
||||||
app.use(function* () {
|
app.use(function* () {
|
||||||
|
if (this.url === '/headerSent') {
|
||||||
|
this.body = 'foo';
|
||||||
|
const that = this;
|
||||||
|
setTimeout(function() {
|
||||||
|
that[fname]('Email');
|
||||||
|
}, 10);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
this.body = {
|
this.body = {
|
||||||
email: this[fname]('Email'),
|
email: this[fname]('Email'),
|
||||||
name: this[fname]('model.user.fields.name'),
|
name: this[fname]('model.user.fields.name'),
|
||||||
|
|
Loading…
Reference in New Issue