From d15d4aa25bbc7989d3d5bbda246b331bdd8ea286 Mon Sep 17 00:00:00 2001 From: bangbang93 Date: Thu, 8 Nov 2018 16:20:33 +0800 Subject: [PATCH] setup ci --- .travis.yml | 20 +++++++++++++ package-lock.json | 74 +++++++++++++++++++++++++++++++++++++++++++++++ package.json | 11 +++++-- test/index.ts | 56 ++++++++++++++++++++++------------- tsconfig.json | 3 ++ 5 files changed, 142 insertions(+), 22 deletions(-) create mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..dd44afc --- /dev/null +++ b/.travis.yml @@ -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 diff --git a/package-lock.json b/package-lock.json index c83a6b4..6a775df 100644 --- a/package-lock.json +++ b/package-lock.json @@ -69,6 +69,12 @@ "integrity": "sha512-tHq6qdbT9U1IRSGf14CL0pUlULksvY9OZ+5eEgl1N7t+OA3tGvNpxJCzuKQlsNgCVwbAs670L1vcVQi8j9HjnA==", "dev": true }, + "@types/mocha": { + "version": "5.2.5", + "resolved": "https://registry.npmjs.org/@types/mocha/-/mocha-5.2.5.tgz", + "integrity": "sha512-lAVp+Kj54ui/vLUFxsJTMtWvZraZxum3w3Nwkble2dNuV5VnPA+Mi2oGX9XYJAaIvZi3tn3cbjS/qcJXRb6Bww==", + "dev": true + }, "@types/mongodb": { "version": "3.1.14", "resolved": "https://registry.npmjs.org/@types/mongodb/-/mongodb-3.1.14.tgz", @@ -189,6 +195,12 @@ "concat-map": "0.0.1" } }, + "browser-stdout": { + "version": "1.3.1", + "resolved": "https://registry.npmjs.org/browser-stdout/-/browser-stdout-1.3.1.tgz", + "integrity": "sha512-qhAVI1+Av2X7qelOfAIYwXONood6XlZE/fXaBSmW/T5SzLAmCgzi+eiWE7fUvbHaeNBQH13UftjpXxsfLkMpgw==", + "dev": true + }, "bson": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/bson/-/bson-1.1.0.tgz", @@ -335,6 +347,12 @@ "integrity": "sha512-6uHUhOPEBgQ24HM+r6b/QwWfZq+yiFcipKFrOFiBEnWdy5sdzYoi+pJeQaPI5qOLRFqWmAXUPQNsielzdLoecA==", "dev": true }, + "growl": { + "version": "1.10.5", + "resolved": "https://registry.npmjs.org/growl/-/growl-1.10.5.tgz", + "integrity": "sha512-qBr4OuELkhPenW6goKVXiv47US3clb3/IbuWF9KNKEijAy9oeHxU9IgzjvJhHkUzhaj7rOUD7+YGWqUjLp5oSA==", + "dev": true + }, "handlebars": { "version": "4.0.12", "resolved": "https://registry.npmjs.org/handlebars/-/handlebars-4.0.12.tgz", @@ -362,6 +380,12 @@ "integrity": "sha1-tdRU3CGZriJWmfNGfloH87lVuv0=", "dev": true }, + "he": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/he/-/he-1.1.1.tgz", + "integrity": "sha1-k0EP0hsAlzUVH4howvJx80J+I/0=", + "dev": true + }, "highlight.js": { "version": "9.13.1", "resolved": "https://registry.npmjs.org/highlight.js/-/highlight.js-9.13.1.tgz", @@ -484,6 +508,56 @@ } } }, + "mocha": { + "version": "5.2.0", + "resolved": "https://registry.npmjs.org/mocha/-/mocha-5.2.0.tgz", + "integrity": "sha512-2IUgKDhc3J7Uug+FxMXuqIyYzH7gJjXECKe/w43IGgQHTSj3InJi+yAA7T24L9bQMRKiUEHxEX37G5JpVUGLcQ==", + "dev": true, + "requires": { + "browser-stdout": "1.3.1", + "commander": "2.15.1", + "debug": "3.1.0", + "diff": "3.5.0", + "escape-string-regexp": "1.0.5", + "glob": "7.1.2", + "growl": "1.10.5", + "he": "1.1.1", + "minimatch": "3.0.4", + "mkdirp": "0.5.1", + "supports-color": "5.4.0" + }, + "dependencies": { + "commander": { + "version": "2.15.1", + "resolved": "http://registry.npmjs.org/commander/-/commander-2.15.1.tgz", + "integrity": "sha512-VlfT9F3V0v+jr4yxPc5gg9s62/fIVWsd2Bk2iD435um1NlGMYdVCq+MjcXnhYq2icNOizHr1kK+5TI6H0Hy0ag==", + "dev": true + }, + "glob": { + "version": "7.1.2", + "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.2.tgz", + "integrity": "sha512-MJTUg1kjuLeQCJ+ccE4Vpa6kKVXkPYJ2mOCQyUuKLcLQsdrMCpBPUi8qVE6+YuaJkozeA9NusTAw3hLr8Xe5EQ==", + "dev": true, + "requires": { + "fs.realpath": "^1.0.0", + "inflight": "^1.0.4", + "inherits": "2", + "minimatch": "^3.0.4", + "once": "^1.3.0", + "path-is-absolute": "^1.0.0" + } + }, + "supports-color": { + "version": "5.4.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.4.0.tgz", + "integrity": "sha512-zjaXglF5nnWpsq470jSv6P9DwPvgLkuapYmfDm3JWOm0vkNTVF2tI4UrN2r6jH1qM/uc/WtxYY1hYoA2dOKj5w==", + "dev": true, + "requires": { + "has-flag": "^3.0.0" + } + } + } + }, "mongodb": { "version": "3.1.8", "resolved": "https://registry.npmjs.org/mongodb/-/mongodb-3.1.8.tgz", diff --git a/package.json b/package.json index 4d9d196..e3a3fdd 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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", @@ -31,5 +35,8 @@ }, "dependencies": { "reflect-metadata": "^0.1.12" - } + }, + "files": [ + "lib/**" + ] } diff --git a/test/index.ts b/test/index.ts index 28b12dc..b8582e8 100644 --- a/test/index.ts +++ b/test/index.ts @@ -33,24 +33,6 @@ class User { type IUserDocument = DocumentType type IUserModel = ModelType & 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 { @@ -76,6 +58,40 @@ class Organization { type IOrganizationDocument = DocumentType type IOrganizationModel = ModelType & 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() +}) diff --git a/tsconfig.json b/tsconfig.json index 227d721..7692d6e 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -10,6 +10,9 @@ "emitDecoratorMetadata": true, "outDir": "lib" }, + "include": [ + "src" + ], "exclude": [ "node_modules" ]