Skip to content

Commit

Permalink
🤖 TEST: Run test on Node.js 18 (#86)
Browse files Browse the repository at this point in the history
  • Loading branch information
fengmk2 authored Aug 19, 2022
1 parent ae56e05 commit 2cd4789
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 6 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
strategy:
fail-fast: false
matrix:
node-version: [8, 10, 12, 14, 16]
node-version: [8, 10, 12, 14, 16, 18]
os: [ubuntu-latest]

steps:
Expand All @@ -35,7 +35,7 @@ jobs:
node-version: ${{ matrix.node-version }}

- name: Install Dependencies
run: npm i -g npminstall && npminstall
run: npm i -g npminstall@5 && npminstall

- name: Continuous Integration
run: npm run ci
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
This software is licensed under the MIT License.

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

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"vary": "^1.1.2"
},
"devDependencies": {
"egg-ci": "^1.19.0",
"egg-ci": "^1.19.1",
"eslint": "^5.15.1",
"eslint-config-egg": "^7.1.0",
"git-contributor": "^1.0.10",
Expand Down Expand Up @@ -46,7 +46,7 @@
"node": ">= 8.0.0"
},
"ci": {
"version": "8, 10, 12, 14, 16",
"version": "8, 10, 12, 14, 16, 18",
"type": "github",
"os": {
"github": "linux"
Expand Down
42 changes: 41 additions & 1 deletion test/cors.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const assert = require('assert');
const Koa = require('koa');
const request = require('supertest');
const cors = require('../');
const cors = require('..');

describe('cors.test.js', function() {
describe('default options', function() {
Expand Down Expand Up @@ -167,6 +167,46 @@ describe('cors.test.js', function() {
});
});

describe('options.origin=promise', function() {
const app = new Koa();
app.use(cors({
origin(ctx) {
return new Promise(resolve => {
setTimeout(() => {
if (ctx.url === '/forbin') {
return resolve(false);
}
return resolve('*');
}, 100);
});
},
}));
app.use(function(ctx) {
ctx.body = { foo: 'bar' };
});

it('should disable cors', function(done) {
request(app.listen())
.get('/forbin')
.set('Origin', 'http://koajs.com')
.expect({ foo: 'bar' })
.expect(200, function(err, res) {
assert(!err);
assert(!res.headers['access-control-allow-origin']);
done();
});
});

it('should set access-control-allow-origin to *', function(done) {
request(app.listen())
.get('/')
.set('Origin', 'http://koajs.com')
.expect({ foo: 'bar' })
.expect('Access-Control-Allow-Origin', '*')
.expect(200, done);
});
});

describe('options.origin=async function', function() {
const app = new Koa();
app.use(cors({
Expand Down

0 comments on commit 2cd4789

Please sign in to comment.