Skip to content

Commit

Permalink
setup ci
Browse files Browse the repository at this point in the history
  • Loading branch information
bangbang93 committed Nov 8, 2018
1 parent 3d985af commit d15d4aa
Show file tree
Hide file tree
Showing 5 changed files with 142 additions and 22 deletions.
20 changes: 20 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
language: node_js
before_script:
- npm run build
node_js:
- "6"
- "8"
- "9"
- "10"
sudo: false
script:
- npm test
- npm run doc

deploy:
provider: pages
skip-cleanup: true
github-token: $GITHUB_TOKEN # Set in the settings page of your repository, as a secure variable
keep-history: true
on:
branch: master
74 changes: 74 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 9 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
"main": "index.js",
"scripts": {
"build": "tsc",
"doc": "typedoc --out doc src/index.ts"
"doc": "typedoc --out doc src/index.ts",
"prepublishOnly": "npm run build",
"test": "mocha --require ts-node/register/transpile-only test/index.ts"
},
"repository": {
"type": "git",
Expand All @@ -21,7 +23,9 @@
"mongoose": "^5.3.10"
},
"devDependencies": {
"@types/mocha": "^5.2.5",
"@types/mongoose": "^5.3.1",
"mocha": "^5.2.0",
"mongoose": "^5.3.10",
"should": "^13.2.3",
"ts-node": "^7.0.1",
Expand All @@ -31,5 +35,8 @@
},
"dependencies": {
"reflect-metadata": "^0.1.12"
}
},
"files": [
"lib/**"
]
}
56 changes: 36 additions & 20 deletions test/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,24 +33,6 @@ class User {
type IUserDocument = DocumentType<User>
type IUserModel = ModelType<User> & typeof User

const UserModel: IUserModel = getModel(User)

UserModel.should.hasOwnProperty('findByName')
const user = new UserModel({
username: 'abc',
password: 'wow',
addresses: [{
country: 'china',
city: 'hangzhou',
address: 'xihu',
}],
})

user.save().should
.rejectedWith('user validation failed: addresses.0.province: Path `province` is required.')

user.addresses[0].country.should.eql('china')

@model('organization')
@index({user: 1, name: 1}, {unique: true})
class Organization {
Expand All @@ -76,6 +58,40 @@ class Organization {
type IOrganizationDocument = DocumentType<Organization>
type IOrganizationModel = ModelType<Organization> & typeof Organization

const OrganizationModel: IOrganizationModel = getModel(Organization)
describe('User', function (this) {
let UserModel: IUserModel
it('getModel', function (this) {
UserModel = getModel(User)
UserModel.should.hasOwnProperty('findByName')
})

it('document', async function (this) {
const user = new UserModel({
username: 'abc',
password: 'wow',
addresses: [{
country: 'china',
city: 'hangzhou',
address: 'xihu',
}],
})

user.addresses[0].country.should.eql('china')

OrganizationModel.should.hasOwnProperty('listByUser')
await user.save().should
.rejectedWith('user validation failed: addresses.0.province: Path `province` is required.')

})
})

describe('organization', function (this) {
let OrganizationModel: IOrganizationModel
it('getModel', function (this) {
OrganizationModel = getModel(Organization)
OrganizationModel.should.hasOwnProperty('listByUser')
})
})

after(async function (this) {
await mongoose.disconnect()
})
3 changes: 3 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
"emitDecoratorMetadata": true,
"outDir": "lib"
},
"include": [
"src"
],
"exclude": [
"node_modules"
]
Expand Down

0 comments on commit d15d4aa

Please sign in to comment.