Skip to content

Commit 2cd4789

Browse files
authoredAug 19, 2022
🤖 TEST: Run test on Node.js 18 (#86)
1 parent ae56e05 commit 2cd4789

File tree

4 files changed

+46
-6
lines changed

4 files changed

+46
-6
lines changed
 

‎.github/workflows/nodejs.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222
strategy:
2323
fail-fast: false
2424
matrix:
25-
node-version: [8, 10, 12, 14, 16]
25+
node-version: [8, 10, 12, 14, 16, 18]
2626
os: [ubuntu-latest]
2727

2828
steps:
@@ -35,7 +35,7 @@ jobs:
3535
node-version: ${{ matrix.node-version }}
3636

3737
- name: Install Dependencies
38-
run: npm i -g npminstall && npminstall
38+
run: npm i -g npminstall@5 && npminstall
3939

4040
- name: Continuous Integration
4141
run: npm run ci

‎LICENSE

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
This software is licensed under the MIT License.
22

3-
Copyright (c) 2015 - 2018 koajs and other contributors
3+
Copyright (c) 2015 - present koajs and other contributors
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

‎package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"vary": "^1.1.2"
1818
},
1919
"devDependencies": {
20-
"egg-ci": "^1.19.0",
20+
"egg-ci": "^1.19.1",
2121
"eslint": "^5.15.1",
2222
"eslint-config-egg": "^7.1.0",
2323
"git-contributor": "^1.0.10",
@@ -46,7 +46,7 @@
4646
"node": ">= 8.0.0"
4747
},
4848
"ci": {
49-
"version": "8, 10, 12, 14, 16",
49+
"version": "8, 10, 12, 14, 16, 18",
5050
"type": "github",
5151
"os": {
5252
"github": "linux"

‎test/cors.test.js

+41-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
const assert = require('assert');
44
const Koa = require('koa');
55
const request = require('supertest');
6-
const cors = require('../');
6+
const cors = require('..');
77

88
describe('cors.test.js', function() {
99
describe('default options', function() {
@@ -167,6 +167,46 @@ describe('cors.test.js', function() {
167167
});
168168
});
169169

170+
describe('options.origin=promise', function() {
171+
const app = new Koa();
172+
app.use(cors({
173+
origin(ctx) {
174+
return new Promise(resolve => {
175+
setTimeout(() => {
176+
if (ctx.url === '/forbin') {
177+
return resolve(false);
178+
}
179+
return resolve('*');
180+
}, 100);
181+
});
182+
},
183+
}));
184+
app.use(function(ctx) {
185+
ctx.body = { foo: 'bar' };
186+
});
187+
188+
it('should disable cors', function(done) {
189+
request(app.listen())
190+
.get('/forbin')
191+
.set('Origin', 'http://koajs.com')
192+
.expect({ foo: 'bar' })
193+
.expect(200, function(err, res) {
194+
assert(!err);
195+
assert(!res.headers['access-control-allow-origin']);
196+
done();
197+
});
198+
});
199+
200+
it('should set access-control-allow-origin to *', function(done) {
201+
request(app.listen())
202+
.get('/')
203+
.set('Origin', 'http://koajs.com')
204+
.expect({ foo: 'bar' })
205+
.expect('Access-Control-Allow-Origin', '*')
206+
.expect(200, done);
207+
});
208+
});
209+
170210
describe('options.origin=async function', function() {
171211
const app = new Koa();
172212
app.use(cors({

0 commit comments

Comments
 (0)
Please sign in to comment.