From 96b996695bd18fe2aa686160c77bea42072220f3 Mon Sep 17 00:00:00 2001 From: Cody Chan Date: Mon, 9 Sep 2019 01:21:40 +0800 Subject: [PATCH] feat: add tests --- template/_package.json | 9 +++++++-- template/test/index.js | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 2 deletions(-) create mode 100644 template/test/index.js diff --git a/template/_package.json b/template/_package.json index c11688e..9148e78 100644 --- a/template/_package.json +++ b/template/_package.json @@ -13,15 +13,20 @@ }, "author": "<%= author %>", "scripts": { + "test": "mocha", "lint": "eslint \"**/*.js\"", - "lint:fix": "eslint \"**/*.js\" --fix" + "lint:fix": "eslint \"**/*.js\" --fix", + "prepublishOnly": "npm run lint && npm run test" }, "dependencies": {}, "devDependencies": { "@svrx/eslint-config": "^1.0.0", + "chai": "^4.2.0", + "chai-json-schema": "^1.5.1", "eslint": "^6.2.0", "husky": "^3.0.4", - "lint-staged": "^9.2.3" + "lint-staged": "^9.2.3", + "mocha": "^6.2.0" }, "husky": { "hooks": { diff --git a/template/test/index.js b/template/test/index.js new file mode 100644 index 0000000..f60981e --- /dev/null +++ b/template/test/index.js @@ -0,0 +1,40 @@ +const chai = require('chai'); + +const { + assets = {}, +} = require('../index'); + +chai.use(require('chai-json-schema')); + +const { assert } = chai; + +const assetsSchema = { + title: 'assets schema', + type: 'object', + properties: { + test: { + type: 'boolean', + }, + script: { + type: 'array', + uniqueItems: true, + items: { + type: 'string', + }, + }, + style: { + type: 'array', + uniqueItems: true, + items: { + type: 'string', + }, + }, + }, +}; + +describe('Format', () => { + it('assets schema', () => { + assert.jsonSchema(assets, assetsSchema); + }); + // TODO: add more tests +});