From 0b204a3048ca756438160d01e73ca2bbe1e8c267 Mon Sep 17 00:00:00 2001 From: Rikki Schulte Date: Sun, 17 Nov 2019 19:27:58 -0500 Subject: [PATCH] ci: fix jest/cypress clash that broke eslint locally --- .eslintrc.js | 20 +++++--- package.json | 1 + packages/codemirror-graphql/.npmignore | 4 -- packages/codemirror-graphql/package.json | 20 ++++++-- packages/graphiql/.babelrc.js | 1 - packages/graphiql/package.json | 2 +- .../package.json | 2 +- .../package.json | 6 ++- .../src/file.spec.ts | 4 +- .../tsconfig.esm.json | 7 ++- .../tsconfig.json | 7 ++- resources/renameFileExtensions.js | 51 +++++++++++++------ yarn.lock | 9 +++- 13 files changed, 96 insertions(+), 38 deletions(-) delete mode 100644 packages/codemirror-graphql/.npmignore delete mode 100644 packages/graphiql/.babelrc.js diff --git a/.eslintrc.js b/.eslintrc.js index 8c7ead336db..f3304a7d693 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -5,7 +5,6 @@ * This source code is licensed under the license found in the * LICENSE file in the root directory of this source tree. * - * @flow */ module.exports = { @@ -21,9 +20,9 @@ module.exports = { }, }, settings: { - 'react': { - 'version': 'detect' - } + react: { + version: 'detect', + }, }, // https://github.com/sindresorhus/globals/blob/master/globals.json env: { @@ -33,7 +32,6 @@ module.exports = { jest: true, mocha: true, browser: true, - 'cypress/globals': true }, extends: ['prettier', 'plugin:import/typescript', 'plugin:react/recommended'], @@ -292,9 +290,19 @@ module.exports = { 'prefer-object-spread/prefer-object-spread': 1, }, - plugins: ['babel', 'import', 'flowtype', 'prefer-object-spread', 'cypress'], + plugins: ['babel', 'import', 'flowtype', 'prefer-object-spread'], overrides: [ + // Cypress plugin, global, etc only for cypress directory + // https://github.com/cypress-io/eslint-plugin-cypress + // cypress clashes with jest expect() + { + files: ['**/cypress/**'], + plugins: ['cypress'], + env: { + 'cypress/globals': true, + }, + }, // Rules for TypeScript only { files: ['*.ts', '*.tsx'], diff --git a/package.json b/package.json index df07f39c4cb..878d9cff899 100644 --- a/package.json +++ b/package.json @@ -80,6 +80,7 @@ "jest-environment-jsdom": "^24.8.0", "jest-environment-jsdom-global": "^1.2.0", "lerna": "^3.16.4", + "mkdirp": "^0.5.1", "mocha": "6.1.4", "prettier": "^1.18.2", "rimraf": "^3.0.0", diff --git a/packages/codemirror-graphql/.npmignore b/packages/codemirror-graphql/.npmignore deleted file mode 100644 index 76d2c8e5aab..00000000000 --- a/packages/codemirror-graphql/.npmignore +++ /dev/null @@ -1,4 +0,0 @@ -babel.config.js -.gitignore -resources -src diff --git a/packages/codemirror-graphql/package.json b/packages/codemirror-graphql/package.json index 312abf0add8..21c34de2696 100644 --- a/packages/codemirror-graphql/package.json +++ b/packages/codemirror-graphql/package.json @@ -14,9 +14,21 @@ }, "license": "MIT", "files": [ - "esm", - "*.js", - "*.flow", + "hint.esm.js", + "hint.js", + "hint.js.flow", + "info.esm.js", + "info.js", + "info.js.flow", + "jump.esm.js", + "jump.js", + "jump.js.flow", + "lint.esm.js", + "lint.js", + "lint.js.flow", + "mode.esm.js", + "mode.js", + "mode.js.flow", "utils", "variables", "results" @@ -31,7 +43,7 @@ "build": "yarn build-clean && yarn build-js && yarn build-esm && yarn build-flow .", "build-js": "babel src --root-mode upward --ignore src/__tests__ --out-dir . && babel src --root-mode upward --ignore src/__tests__ --out-dir esm && node ../../resources/renameFileExtensions.js './esm/**/*.js' . .esm.js", "build-esm": "ESM=true babel src --root-mode upward --ignore src/__tests__ --out-dir esm", - "build-clean": "rimraf {mode,hint,info,jump,lint}.{js,js.flow} && rimraf esm results utils variables coverage __tests__", + "build-clean": "rimraf {mode,hint,info,jump,lint}.{js,esm.js,js.flow} && rimraf esm results utils variables coverage __tests__", "build-flow": "node ../../resources/buildFlow.js", "watch": "babel --optional runtime resources/watch.js | node", "prepublish": "node ../../resources/prepublish.js", diff --git a/packages/graphiql/.babelrc.js b/packages/graphiql/.babelrc.js deleted file mode 100644 index e853e0bd7aa..00000000000 --- a/packages/graphiql/.babelrc.js +++ /dev/null @@ -1 +0,0 @@ -module.exports = require('./babel.config') diff --git a/packages/graphiql/package.json b/packages/graphiql/package.json index f56473d7169..ca23db12e50 100644 --- a/packages/graphiql/package.json +++ b/packages/graphiql/package.json @@ -35,7 +35,7 @@ "build-demo": "cp resources/index.html .", "check": "flow check", "dev": "babel-node test/server.js", - "e2e": "yarn e2e:server && cypress run && kill -9 `cat test/pid`", + "e2e": "yarn e2e:server && cypress run", "e2e:server": "PORT=8080 node test/e2e-server & ; wait-on http://localhost:8080", "test": "node ../../resources/runTests ENZYME=true" }, diff --git a/packages/graphql-language-service-types/package.json b/packages/graphql-language-service-types/package.json index 456bb5e2b3e..de2ca417482 100644 --- a/packages/graphql-language-service-types/package.json +++ b/packages/graphql-language-service-types/package.json @@ -22,7 +22,7 @@ ], "main": "dist/index.js", "module": "esm/index.js", - "typings": "src/index.ts", + "typings": "dist/index.d.ts", "scripts": { "build": "yarn run build-ts && yarn run build-flow", "build-ts": "tsc", diff --git a/packages/graphql-language-service-utils/package.json b/packages/graphql-language-service-utils/package.json index b16ebadc339..9da3f79c4de 100644 --- a/packages/graphql-language-service-utils/package.json +++ b/packages/graphql-language-service-utils/package.json @@ -14,8 +14,7 @@ }, "license": "MIT", "files": [ - "dist", - "esm" + "dist" ], "keywords": [ "graphql" @@ -40,5 +39,8 @@ "dependencies": { "graphql-config": "2.2.1", "graphql-language-service-types": "^1.5.0" + }, + "devDependencies": { + "@types/jest": "^24.0.23" } } diff --git a/packages/graphql-language-service-utils/src/file.spec.ts b/packages/graphql-language-service-utils/src/file.spec.ts index 819a3860d04..804baec2ebf 100644 --- a/packages/graphql-language-service-utils/src/file.spec.ts +++ b/packages/graphql-language-service-utils/src/file.spec.ts @@ -60,7 +60,9 @@ describe('requireFile', () => { ); }); it('should require file with no extension using js', async () => { - const config = await requireFile(path.join(__dirname, '../../../jest.config')); + const config = await requireFile( + path.join(__dirname, '../../../jest.config'), + ); await expect(config.collectCoverage).toEqual(true); }); it('should require file with no extension using json', async () => { diff --git a/packages/graphql-language-service-utils/tsconfig.esm.json b/packages/graphql-language-service-utils/tsconfig.esm.json index d85b9ee4b0f..48db40b984a 100644 --- a/packages/graphql-language-service-utils/tsconfig.esm.json +++ b/packages/graphql-language-service-utils/tsconfig.esm.json @@ -3,5 +3,10 @@ "compilerOptions": { "rootDir": "./src", "outDir": "./esm", - } + }, + "references": [ + { + "path": "../graphql-language-service-types" + } + ] } diff --git a/packages/graphql-language-service-utils/tsconfig.json b/packages/graphql-language-service-utils/tsconfig.json index f8d6107f388..3dd18754f9e 100644 --- a/packages/graphql-language-service-utils/tsconfig.json +++ b/packages/graphql-language-service-utils/tsconfig.json @@ -3,5 +3,10 @@ "compilerOptions": { "rootDir": "./src", "outDir": "./dist", - } + }, + "references": [ + { + "path": "../graphql-language-service-types" + } + ] } diff --git a/resources/renameFileExtensions.js b/resources/renameFileExtensions.js index e0b48499773..dd02d5805ea 100644 --- a/resources/renameFileExtensions.js +++ b/resources/renameFileExtensions.js @@ -1,9 +1,10 @@ const copy = require('copy'); const path = require('path'); const fs = require('fs'); -const os = require('os'); +const mkdirp = require('mkdirp'); +const crypto = require('crypto'); +const rimraf = require('rimraf'); -const tmpDir = os.tmpdir(); const [, , src, dest, destExtension] = process.argv; if (!src || !dest || !destExtension) { console.error( @@ -12,19 +13,39 @@ if (!src || !dest || !destExtension) { process.exit(1); } -const tempDirectory = fs.mkdtempSync(`${tmpDir}${path.sep}`); +const coveragePath = path.join(__dirname, `../coverage`); -copy(src, tempDirectory, (error, files) => { - if (error) { - throw error; - } - files.forEach(file => { - if (file.dest) { - const srcExt = path.parse(file.dest).ext; - const destinationPath = file.dest - .replace(srcExt, destExtension) - .replace(tempDirectory, dest); - fs.renameSync(file.dest, path.resolve(destinationPath)); +const tempRenamePath = path.join( + coveragePath, + '.temp', + crypto.randomBytes(20).toString('hex'), +); + +if (fs.existsSync(tempRenamePath)) { + rimraf.sync(tempRenamePath); +} + +const tempPath = mkdirp.sync(tempRenamePath); + +if (tempPath) { + copy(src, tempRenamePath, (error, files) => { + if (error) { + throw error; } + files.forEach(file => { + if (file.dest) { + const srcExt = path.parse(file.dest).ext; + const destinationPath = file.dest + .replace(srcExt, destExtension) // rewrite extension + .replace(tempRenamePath, dest); // and destination path + // move the files and rename them... by renaming them :) + fs.renameSync(file.dest, path.resolve(destinationPath)); + } + }); + // should cleanup temp directory after renaming + // every file to the destination path + rimraf.sync(tempRenamePath); }); -}); +} else { + throw Error(`Could not generate temporary path\n${tempRenamePath}`); +} diff --git a/yarn.lock b/yarn.lock index 91831f728e3..4785c4d5b5e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2556,6 +2556,13 @@ dependencies: "@types/jest-diff" "*" +"@types/jest@^24.0.23": + version "24.0.23" + resolved "https://registry.npmjs.org/@types/jest/-/jest-24.0.23.tgz#046f8e2ade026fe831623e361a36b6fb9a4463e4" + integrity sha512-L7MBvwfNpe7yVPTXLn32df/EK+AMBFAFvZrRuArGs7npEWnlziUXK+5GMIUTI4NIuwok3XibsjXCs5HxviYXjg== + dependencies: + jest-diff "^24.3.0" + "@types/json-schema@^7.0.3": version "7.0.3" resolved "https://registry.yarnpkg.com/@types/json-schema/-/json-schema-7.0.3.tgz#bdfd69d61e464dcc81b25159c270d75a73c1a636" @@ -8325,7 +8332,7 @@ jest-config@^24.9.0: pretty-format "^24.9.0" realpath-native "^1.1.0" -jest-diff@^24.9.0: +jest-diff@^24.3.0, jest-diff@^24.9.0: version "24.9.0" resolved "https://registry.npmjs.org/jest-diff/-/jest-diff-24.9.0.tgz#931b7d0d5778a1baf7452cb816e325e3724055da" integrity sha512-qMfrTs8AdJE2iqrTp0hzh7kTd2PQWrsFyj9tORoKmu32xjPjeE4NyjVRDz8ybYwqS2ik8N4hsIpiVTyFeo2lBQ==