From 5b8db73393925d392ab3c44a262e6d00538d707c Mon Sep 17 00:00:00 2001 From: joelchu Date: Fri, 21 Feb 2020 14:12:46 +0800 Subject: [PATCH 1/5] ava is completely fucked what the fuck wrong with this dick heads --- packages/contract-cli/TODO.md | 4 +++ packages/contract-cli/package.json | 25 +++++++++---------- .../src/generator/get-resolver.js | 2 +- .../contract-cli/src/generator/helpers.js | 4 ++- packages/contract-cli/src/options.js | 8 +++--- 5 files changed, 25 insertions(+), 18 deletions(-) create mode 100644 packages/contract-cli/TODO.md diff --git a/packages/contract-cli/TODO.md b/packages/contract-cli/TODO.md new file mode 100644 index 00000000..3a9bc83d --- /dev/null +++ b/packages/contract-cli/TODO.md @@ -0,0 +1,4 @@ +## 2020-02-21 + +- Need to add a clean up action when pass `development: true` then remove existing contract before start (instead of our current method in the post generate method) +- When `enableAuth: false` but we have resolvers inside the public folder, it should also treat as a correct resolver and add to the contract \ No newline at end of file diff --git a/packages/contract-cli/package.json b/packages/contract-cli/package.json index 2b865fa4..2eca7baf 100755 --- a/packages/contract-cli/package.json +++ b/packages/contract-cli/package.json @@ -1,6 +1,6 @@ { "name": "jsonql-contract", - "version": "1.8.6", + "version": "1.8.7", "description": "JS API / command line tool to generate the contract.json for jsonql", "main": "index.js", "files": [ @@ -12,11 +12,11 @@ ], "scripts": { "dev": "DEBUG=jsonql-contract:* node ./test.js", - "coverage": "nyc ava --verbose", - "prepare": "ava --verbose", + "coverage": "nyc ava", + "prepare": "ava", "cli": "DEBUG=jsonql-contract* node ./cli.js", "cli:watch": "DEBUG=jsonql-contract* node ./watch.js", - "test": "ava --verbose", + "test": "ava", "test:cli": "npm run cli configFile ./tests/fixtures/cmd-config-test.js", "test:doc": "DEBUG=jsonql-contract:* ava ./tests/contract-with-doc.test.js", "test:gen": "DEBUG=jsonql-contract:* ava ./tests/generator.test.js", @@ -58,21 +58,20 @@ "kefir": "^3.8.6", "lodash": "^4.17.15", "nb-split-tasks": "^0.6.0", - "yargs": "^15.0.2" + "yargs": "^15.1.0" }, "devDependencies": { - "ava": "^2.4.0", + "ava": "^3.3.0", "nyc": "^15.0.0", - "request": "^2.88.0" + "request": "^2.88.2" }, "ava": { "files": [ - "tests/**/*.test.js", - "!tests/fixtures/**/*.*" + "tests/**/*.test.js" ], - "sources": [ - "**/*.{js,jsx}", - "!dist/**/*" + "ignoredByWatcher": [ + "dist/**/*", + "tests/fixtures/**/*.*" ], "cache": true, "concurrency": 5, @@ -80,7 +79,7 @@ "failWithoutAssertions": false, "tap": false, "verbose": true, - "compileEnhancements": false + "timeout": "60s" }, "engine": { "node": ">=8" diff --git a/packages/contract-cli/src/generator/get-resolver.js b/packages/contract-cli/src/generator/get-resolver.js index 86bf0297..be7c5919 100644 --- a/packages/contract-cli/src/generator/get-resolver.js +++ b/packages/contract-cli/src/generator/get-resolver.js @@ -83,7 +83,7 @@ const checkResolver = (indexFile, inDir, fileType, config) => (baseFile) => { const fileName = basename(fileParts[1], ext) // const evt = basename(fileParts[1]); switch (ctn) { - case 4: // this will definely inside the public folder + case 4: // this will be inside the public folder if (inTypesArray(type)) { // we need to shift down one level to get the filename const fileName4 = basename(fileParts[2], ext) diff --git a/packages/contract-cli/src/generator/helpers.js b/packages/contract-cli/src/generator/helpers.js index ad70dfc8..d503b2aa 100644 --- a/packages/contract-cli/src/generator/helpers.js +++ b/packages/contract-cli/src/generator/helpers.js @@ -76,12 +76,14 @@ const addSocketProps = function(type, config, obj) { /** * Check if it's a public folder + * 2020-02-21 we remove this line `config.enableAuth === true && ` + * to allow public folder get include into the contract regardless enableAuth * @param {array} files file path split * @param {object} config publicKey replace the PUBLIC_KEY * @return {boolean} true on success or undefined on fail */ const checkIfIsPublic = (files, config) => ( - config.enableAuth === true && files[1] === config.publicMethodDir + files[1] === config.publicMethodDir ) /** diff --git a/packages/contract-cli/src/options.js b/packages/contract-cli/src/options.js index da6a8ef9..a0172116 100644 --- a/packages/contract-cli/src/options.js +++ b/packages/contract-cli/src/options.js @@ -35,9 +35,9 @@ const constProps = { const defaultOptions = { // give the contract an expired time expired: createConfig(0, [NUMBER_TYPE]), - + // passing extra props to the contract.json extraContractProps: createConfig(false, [OBJECT_TYPE], {[OPTIONAL_KEY]: true}), - + // Auth related props loginHandlerName: createConfig(ISSUER_NAME, [STRING_TYPE]), logoutHandlerName: createConfig(LOGOUT_NAME, [STRING_TYPE]), validatorHandlerName: createConfig(VALIDATOR_NAME, [STRING_TYPE, BOOLEAN_TYPE]), @@ -72,7 +72,9 @@ const defaultOptions = { // ported from jsonql-koa buildContractOnStart: constructConfig(false, [BOOLEAN_TYPE], true), // @1.8.x enable or disable the split tasks - enableSplitTask: createConfig(false, [BOOLEAN_TYPE]) + enableSplitTask: createConfig(false, [BOOLEAN_TYPE]), + // add 1.8.7 to determine if we clean out the contract folder or not + development: createConfig(false, [BOOLEAN_TYPE]) } // export it module.exports = config => checkConfigAsync(config, defaultOptions, constProps) -- Gitee From 3ee38a709f50936c23e6a48279a450eac557d13e Mon Sep 17 00:00:00 2001 From: joelchu Date: Fri, 21 Feb 2020 14:19:22 +0800 Subject: [PATCH 2/5] disable the cmd test and test works again --- packages/contract-cli/package.json | 3 ++- packages/node-client/tests/fixtures/jwt/contract.json | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/contract-cli/package.json b/packages/contract-cli/package.json index 2eca7baf..23f365b9 100755 --- a/packages/contract-cli/package.json +++ b/packages/contract-cli/package.json @@ -71,7 +71,8 @@ ], "ignoredByWatcher": [ "dist/**/*", - "tests/fixtures/**/*.*" + "tests/fixtures/**/*.*", + "tests/cmd.test.js" ], "cache": true, "concurrency": 5, diff --git a/packages/node-client/tests/fixtures/jwt/contract.json b/packages/node-client/tests/fixtures/jwt/contract.json index cd53c3d7..40374ac9 100644 --- a/packages/node-client/tests/fixtures/jwt/contract.json +++ b/packages/node-client/tests/fixtures/jwt/contract.json @@ -102,7 +102,7 @@ ] } }, - "timestamp": 1577242325, + "timestamp": 1582265916, "sourceType": "script", "socket": { "gateway": { -- Gitee From 107912d3df31b4ec689f2015e25e11983941a114 Mon Sep 17 00:00:00 2001 From: joelchu Date: Fri, 21 Feb 2020 14:40:38 +0800 Subject: [PATCH 3/5] ava just hang up the system --- packages/contract-cli/package.json | 3 +- .../tests/public-enable-auth-false.test.js | 38 +++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 packages/contract-cli/tests/public-enable-auth-false.test.js diff --git a/packages/contract-cli/package.json b/packages/contract-cli/package.json index 23f365b9..0995d26d 100755 --- a/packages/contract-cli/package.json +++ b/packages/contract-cli/package.json @@ -28,7 +28,8 @@ "test:custom": "DEBUG=jsonql-contract:* ava tests/custom-login.test.js", "test:debug": "DEBUG=jsonql* ava tests/koa-debug.test.js", "test:split": "DEBUG=jsonql-contract* ava tests/split-task.test.js", - "test:dc": "DEBUG=jsonql-contract* ava tests/debug-contract.test.js" + "test:dc": "DEBUG=jsonql-contract* ava tests/debug-contract.test.js", + "test:public": "DEBUG=jsonql-contract:* ava tests/public-enable-auth-false.test.js" }, "keywords": [ "jsonql", diff --git a/packages/contract-cli/tests/public-enable-auth-false.test.js b/packages/contract-cli/tests/public-enable-auth-false.test.js new file mode 100644 index 00000000..d67c7271 --- /dev/null +++ b/packages/contract-cli/tests/public-enable-auth-false.test.js @@ -0,0 +1,38 @@ +// test if it picks up the public folder even when enableAuth is false +const test = require('ava') +const { join } = require('path') +const fsx = require('fs-extra') + +const baseDir = join(__dirname, '..', '..', 'node-client', 'tests', 'fixtures') +const resolverDir = join(baseDir, 'resolvers') + +const contractDir = join(baseDir, 'tmp', 'public') + +const debug = require('debug')('jsonql-contract:test:debug-public') + +const generator = require('../index') + +test.before(async t => { + t.context.result = await generator({ + resolverDir, + contractDir, + + returnAs: 'json', + enableAuth: false + }) +}) + + +test.after(t => { + // fsx.removeSync(contractDir) +}) + +test(`the contract should contain resolver inside the pulic folder`, t => { + + debug(t.context.result) + + t.truthy(t.context.result.query.anyOneCanGetThis) + // t.truthy(result.auth.customLogin) + +}) + -- Gitee From 18c9248694b1fa56bf991b75ab20ff4c92368e5f Mon Sep 17 00:00:00 2001 From: joelchu Date: Fri, 21 Feb 2020 14:50:18 +0800 Subject: [PATCH 4/5] test for new feature to include public folder passed --- .../tests/public-enable-auth-false.test.js | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/packages/contract-cli/tests/public-enable-auth-false.test.js b/packages/contract-cli/tests/public-enable-auth-false.test.js index d67c7271..1ba8d411 100644 --- a/packages/contract-cli/tests/public-enable-auth-false.test.js +++ b/packages/contract-cli/tests/public-enable-auth-false.test.js @@ -1,9 +1,9 @@ -// test if it picks up the public folder even when enableAuth is false +// test if it picks up the public folder even when enableAuth is false const test = require('ava') const { join } = require('path') const fsx = require('fs-extra') -const baseDir = join(__dirname, '..', '..', 'node-client', 'tests', 'fixtures') +const baseDir = join(__dirname, 'fixtures') const resolverDir = join(baseDir, 'resolvers') const contractDir = join(baseDir, 'tmp', 'public') @@ -16,7 +16,7 @@ test.before(async t => { t.context.result = await generator({ resolverDir, contractDir, - + returnAs: 'json', enableAuth: false }) @@ -26,13 +26,10 @@ test.before(async t => { test.after(t => { // fsx.removeSync(contractDir) }) - + test(`the contract should contain resolver inside the pulic folder`, t => { debug(t.context.result) - - t.truthy(t.context.result.query.anyOneCanGetThis) - // t.truthy(result.auth.customLogin) - + + t.truthy(t.context.result.query.anyoneCanGetThis) }) - -- Gitee From a146fe863179e55bcde57857cccc44f0d6084c20 Mon Sep 17 00:00:00 2001 From: joelchu Date: Fri, 21 Feb 2020 14:58:38 +0800 Subject: [PATCH 5/5] test all passed ready to PR --- packages/contract-cli/TODO.md | 4 ++-- packages/contract-cli/package.json | 3 +-- packages/node-client/tests/fixtures/jwt/contract.json | 2 +- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/packages/contract-cli/TODO.md b/packages/contract-cli/TODO.md index 3a9bc83d..38ac1e90 100644 --- a/packages/contract-cli/TODO.md +++ b/packages/contract-cli/TODO.md @@ -1,4 +1,4 @@ -## 2020-02-21 +## 2020-02-21 - Need to add a clean up action when pass `development: true` then remove existing contract before start (instead of our current method in the post generate method) -- When `enableAuth: false` but we have resolvers inside the public folder, it should also treat as a correct resolver and add to the contract \ No newline at end of file +- When `enableAuth: false` TBC if `development:true` should we include those resolvers inside the private folder as well diff --git a/packages/contract-cli/package.json b/packages/contract-cli/package.json index 0995d26d..47fa1311 100755 --- a/packages/contract-cli/package.json +++ b/packages/contract-cli/package.json @@ -63,8 +63,7 @@ }, "devDependencies": { "ava": "^3.3.0", - "nyc": "^15.0.0", - "request": "^2.88.2" + "nyc": "^15.0.0" }, "ava": { "files": [ diff --git a/packages/node-client/tests/fixtures/jwt/contract.json b/packages/node-client/tests/fixtures/jwt/contract.json index 40374ac9..136cadac 100644 --- a/packages/node-client/tests/fixtures/jwt/contract.json +++ b/packages/node-client/tests/fixtures/jwt/contract.json @@ -102,7 +102,7 @@ ] } }, - "timestamp": 1582265916, + "timestamp": 1582268247, "sourceType": "script", "socket": { "gateway": { -- Gitee