From 3bf2196388033a026cb1e1e6317d33632c9bea75 Mon Sep 17 00:00:00 2001 From: "Juan Picado @jotadeveloper" Date: Sun, 15 Dec 2019 08:52:55 +0100 Subject: [PATCH] chore: reorganize setup files --- .circleci/config.yml | 2 +- .eslintrc | 6 +-- package.json | 2 +- test/.eslintrc | 3 +- test/e2e-cli/.eslintrc | 6 +++ .../config/_bootstrap_verdaccio.yaml | 0 test/{e2e-pkg => e2e-cli}/env_babel.js | 0 test/e2e-cli/env_setup.js | 4 ++ test/e2e-cli/env_teardown.js | 4 ++ .../jest.config.e2e.cli.js} | 4 +- .../projects/basic/.npmignore | 0 .../projects/basic/README.md | 0 .../projects/basic/index.js | 0 .../projects/basic/package.json | 1 + .../projects/scoped_basic/.npmignore | 0 .../projects/scoped_basic/README.md | 0 .../projects/scoped_basic/index.js | 0 .../projects/scoped_basic/package.json | 0 test/e2e-cli/setup/setup.ts | 29 +++++++++++ test/e2e-cli/setup/teardown.ts | 4 ++ test/e2e-cli/setup/test_environment.ts | 28 +++++++++++ test/e2e-cli/test/install/install.spec.ts | 29 +++++++++++ .../test/publish/publish.private.pkg.spec.ts | 6 ++- test/{e2e-pkg => e2e-cli}/utils/global.js | 0 test/{e2e-pkg => e2e-cli}/utils/process.js | 0 test/e2e-pkg/setup/test_environment.ts | 49 ------------------- 26 files changed, 120 insertions(+), 57 deletions(-) create mode 100644 test/e2e-cli/.eslintrc rename test/{e2e-pkg => e2e-cli}/config/_bootstrap_verdaccio.yaml (100%) rename test/{e2e-pkg => e2e-cli}/env_babel.js (100%) create mode 100644 test/e2e-cli/env_setup.js create mode 100644 test/e2e-cli/env_teardown.js rename test/{e2e-pkg/jest.config.e2e.pkg.js => e2e-cli/jest.config.e2e.cli.js} (70%) rename test/{e2e-pkg => e2e-cli}/projects/basic/.npmignore (100%) rename test/{e2e-pkg => e2e-cli}/projects/basic/README.md (100%) rename test/{e2e-pkg => e2e-cli}/projects/basic/index.js (100%) rename test/{e2e-pkg => e2e-cli}/projects/basic/package.json (93%) rename test/{e2e-pkg => e2e-cli}/projects/scoped_basic/.npmignore (100%) rename test/{e2e-pkg => e2e-cli}/projects/scoped_basic/README.md (100%) rename test/{e2e-pkg => e2e-cli}/projects/scoped_basic/index.js (100%) rename test/{e2e-pkg => e2e-cli}/projects/scoped_basic/package.json (100%) create mode 100644 test/e2e-cli/setup/setup.ts create mode 100644 test/e2e-cli/setup/teardown.ts create mode 100644 test/e2e-cli/setup/test_environment.ts create mode 100644 test/e2e-cli/test/install/install.spec.ts rename test/{e2e-pkg => e2e-cli}/test/publish/publish.private.pkg.spec.ts (86%) rename test/{e2e-pkg => e2e-cli}/utils/global.js (100%) rename test/{e2e-pkg => e2e-cli}/utils/process.js (100%) delete mode 100644 test/e2e-pkg/setup/test_environment.ts diff --git a/.circleci/config.yml b/.circleci/config.yml index de5147b6c..bc60f04b0 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -117,7 +117,7 @@ jobs: - restore_repo - run: name: Test End-to-End ClI - command: yarn run test:e2e:pkg + command: yarn run test:e2e:cli coverage: <<: *defaults diff --git a/.eslintrc b/.eslintrc index a7443349a..881e7792c 100644 --- a/.eslintrc +++ b/.eslintrc @@ -3,10 +3,10 @@ "@verdaccio" ], "rules": { - "@typescript-eslint/no-var-requires": ["warn"], + "@typescript-eslint/no-var-requires": 0, "@typescript-eslint/ban-ts-ignore": 0, - "@typescript-eslint/no-inferrable-types": ["warn"], - "@typescript-eslint/no-empty-function": ["warn"], + "@typescript-eslint/no-inferrable-types": 0, + "@typescript-eslint/no-empty-function": 0, "@typescript-eslint/no-this-alias": ["warn"], "@typescript-eslint/no-use-before-define": 0, "@typescript-eslint/array-type": ["warn"], diff --git a/package.json b/package.json index 069448dac..3c0e2e4dc 100644 --- a/package.json +++ b/package.json @@ -117,7 +117,7 @@ "test:clean": "npx jest --clearCache", "test:unit": "cross-env NODE_ENV=test BABEL_ENV=test TZ=UTC FORCE_COLOR=1 jest --config ./jest.config.js --maxWorkers 2 --passWithNoTests", "test:functional": "cross-env NODE_ENV=test jest --config ./test/jest.config.functional.js --testPathPattern ./test/functional/index* --passWithNoTests", - "test:e2e:pkg": "cross-env NODE_ENV=test jest --config ./test/e2e-pkg/jest.config.e2e.pkg.js --passWithNoTests", + "test:e2e:cli": "cross-env NODE_ENV=test jest --config ./test/e2e-cli/jest.config.e2e.cli.js --passWithNoTests", "test:e2e": "cross-env BABEL_ENV=test jest --config ./test/jest.config.e2e.js", "test:all": "npm run test && npm run test:functional && npm run test:e2e & npm run test:e2e:pkg", "pre:ci": "npm run lint", diff --git a/test/.eslintrc b/test/.eslintrc index d462ff13f..b2c8bc5d2 100644 --- a/test/.eslintrc +++ b/test/.eslintrc @@ -24,6 +24,7 @@ } ], "no-useless-escape": 0, - "@typescript-eslint/explicit-function-return-type": 0 + "@typescript-eslint/explicit-function-return-type": 0, + "@typescript-eslint/no-empty-function": 0 } } diff --git a/test/e2e-cli/.eslintrc b/test/e2e-cli/.eslintrc new file mode 100644 index 000000000..cbfb89d2f --- /dev/null +++ b/test/e2e-cli/.eslintrc @@ -0,0 +1,6 @@ +{ + "rules": { + "@typescript-eslint/no-var-requires": 0, + "@typescript-eslint/explicit-member-accessibility": 0 + } +} diff --git a/test/e2e-pkg/config/_bootstrap_verdaccio.yaml b/test/e2e-cli/config/_bootstrap_verdaccio.yaml similarity index 100% rename from test/e2e-pkg/config/_bootstrap_verdaccio.yaml rename to test/e2e-cli/config/_bootstrap_verdaccio.yaml diff --git a/test/e2e-pkg/env_babel.js b/test/e2e-cli/env_babel.js similarity index 100% rename from test/e2e-pkg/env_babel.js rename to test/e2e-cli/env_babel.js diff --git a/test/e2e-cli/env_setup.js b/test/e2e-cli/env_setup.js new file mode 100644 index 000000000..222f7183e --- /dev/null +++ b/test/e2e-cli/env_setup.js @@ -0,0 +1,4 @@ +require('@babel/register')({ + extensions: [".ts", ".js"] +}); +module.exports = require('./setup/setup'); diff --git a/test/e2e-cli/env_teardown.js b/test/e2e-cli/env_teardown.js new file mode 100644 index 000000000..75165a7c7 --- /dev/null +++ b/test/e2e-cli/env_teardown.js @@ -0,0 +1,4 @@ +require('@babel/register')({ + extensions: [".ts", ".js"] +}); +module.exports = require('./setup/teardown'); diff --git a/test/e2e-pkg/jest.config.e2e.pkg.js b/test/e2e-cli/jest.config.e2e.cli.js similarity index 70% rename from test/e2e-pkg/jest.config.e2e.pkg.js rename to test/e2e-cli/jest.config.e2e.cli.js index 7d9476a00..5cec14386 100644 --- a/test/e2e-pkg/jest.config.e2e.pkg.js +++ b/test/e2e-cli/jest.config.e2e.cli.js @@ -1,10 +1,12 @@ const { defaults } = require('jest-config'); module.exports = { - name: 'verdaccio-e2e-pkg-jest', + name: 'verdaccio-e2e-cli-jest', verbose: true, collectCoverage: false, moduleFileExtensions: [...defaults.moduleFileExtensions, 'ts'], testEnvironment: './env_babel.js', + globalSetup: './env_setup.js', + globalTeardown: './env_teardown.js', testRegex: '(/test/e2e.*\\.spec)\\.ts' }; diff --git a/test/e2e-pkg/projects/basic/.npmignore b/test/e2e-cli/projects/basic/.npmignore similarity index 100% rename from test/e2e-pkg/projects/basic/.npmignore rename to test/e2e-cli/projects/basic/.npmignore diff --git a/test/e2e-pkg/projects/basic/README.md b/test/e2e-cli/projects/basic/README.md similarity index 100% rename from test/e2e-pkg/projects/basic/README.md rename to test/e2e-cli/projects/basic/README.md diff --git a/test/e2e-pkg/projects/basic/index.js b/test/e2e-cli/projects/basic/index.js similarity index 100% rename from test/e2e-pkg/projects/basic/index.js rename to test/e2e-cli/projects/basic/index.js diff --git a/test/e2e-pkg/projects/basic/package.json b/test/e2e-cli/projects/basic/package.json similarity index 93% rename from test/e2e-pkg/projects/basic/package.json rename to test/e2e-cli/projects/basic/package.json index 26eb5c0c7..7f1dec508 100644 --- a/test/e2e-pkg/projects/basic/package.json +++ b/test/e2e-cli/projects/basic/package.json @@ -11,6 +11,7 @@ "sample" ], "dependencies": { + "jquery": "^3.4.1", "lodash": "^4.17.15" }, "author": "Juan Picado ", diff --git a/test/e2e-pkg/projects/scoped_basic/.npmignore b/test/e2e-cli/projects/scoped_basic/.npmignore similarity index 100% rename from test/e2e-pkg/projects/scoped_basic/.npmignore rename to test/e2e-cli/projects/scoped_basic/.npmignore diff --git a/test/e2e-pkg/projects/scoped_basic/README.md b/test/e2e-cli/projects/scoped_basic/README.md similarity index 100% rename from test/e2e-pkg/projects/scoped_basic/README.md rename to test/e2e-cli/projects/scoped_basic/README.md diff --git a/test/e2e-pkg/projects/scoped_basic/index.js b/test/e2e-cli/projects/scoped_basic/index.js similarity index 100% rename from test/e2e-pkg/projects/scoped_basic/index.js rename to test/e2e-cli/projects/scoped_basic/index.js diff --git a/test/e2e-pkg/projects/scoped_basic/package.json b/test/e2e-cli/projects/scoped_basic/package.json similarity index 100% rename from test/e2e-pkg/projects/scoped_basic/package.json rename to test/e2e-cli/projects/scoped_basic/package.json diff --git a/test/e2e-cli/setup/setup.ts b/test/e2e-cli/setup/setup.ts new file mode 100644 index 000000000..3f60036ab --- /dev/null +++ b/test/e2e-cli/setup/setup.ts @@ -0,0 +1,29 @@ +import fs from "fs"; +import path from "path"; +import os from "os"; +import {yellow} from "kleur"; +import {spawn} from "child_process"; +import { npm } from '../utils/process'; +import * as __global from '../utils/global.js'; + +module.exports = async () => { + const tempRoot = fs.mkdtempSync(path.join(fs.realpathSync(os.tmpdir()), 'verdaccio-cli-e2e-')); + __global.addItem('dir-root', tempRoot); + console.log(yellow(`Add temp root folder: ${tempRoot}`)); + fs.copyFileSync( + path.join(__dirname, '../config/_bootstrap_verdaccio.yaml'), + path.join(tempRoot, 'verdaccio.yaml'), + ); + // @ts-ignore + global.__namespace = __global; + console.log(`current directory: ${process.cwd()}`); + // @ts-ignore + global.registryProcess = spawn( + 'node', + [require.resolve('verdaccio/bin/verdaccio'), '-c', './verdaccio.yaml'], + { cwd: tempRoot, stdio: 'inherit' }, + ); + + // publish current build version on local registry + await npm('publish', '--registry' ,'http://localhost:4873'); +} diff --git a/test/e2e-cli/setup/teardown.ts b/test/e2e-cli/setup/teardown.ts new file mode 100644 index 000000000..346c5c595 --- /dev/null +++ b/test/e2e-cli/setup/teardown.ts @@ -0,0 +1,4 @@ +module.exports = async function() { + // @ts-ignore + global.registryProcess.kill(); +}; diff --git a/test/e2e-cli/setup/test_environment.ts b/test/e2e-cli/setup/test_environment.ts new file mode 100644 index 000000000..17efe02da --- /dev/null +++ b/test/e2e-cli/setup/test_environment.ts @@ -0,0 +1,28 @@ +const fs = require('fs'); +import os from 'os'; +import path from 'path'; +import NodeEnvironment from 'jest-environment-node'; +const __global = require('../utils/global'); +// import { npm } from '../utils/process'; + + +class PuppeteerEnvironment extends NodeEnvironment { + constructor(config) { + super(config) + } + + async setup() { + const tempRoot = fs.mkdtempSync(path.join(fs.realpathSync(os.tmpdir()), 'verdaccio-suite-test-')); + __global.addItem('dir-root', tempRoot); + this.global.__namespace = __global; + console.log(`current directory: ${process.cwd()}`); + } + + async teardown() {} + + runScript(script) { + return super.runScript(script); + } +} + +export default PuppeteerEnvironment; diff --git a/test/e2e-cli/test/install/install.spec.ts b/test/e2e-cli/test/install/install.spec.ts new file mode 100644 index 000000000..47e0ff28e --- /dev/null +++ b/test/e2e-cli/test/install/install.spec.ts @@ -0,0 +1,29 @@ +import path from 'path'; +import { npm } from '../../utils/process'; + +function testExample() { + console.log('running example'); + return Promise.resolve(true); +} + +export default async function() { + await testExample(); +} + +describe('npm install', ()=> { + + beforeAll(() => { + + }); + + test('should install jquery', async () => { + console.log(`New directory: ${process.cwd()}`, __dirname); + process.chdir(path.join(__dirname, '../../projects/basic')); + console.log(`New directory: ${process.cwd()}`); + await npm('install', 'jquery', '--registry' ,'http://localhost:4873'); + + // @ts-ignore + // console.log('--->', global.__namespace.getItem('dir-root')); + expect(true).toBe(true); + }) +}); diff --git a/test/e2e-pkg/test/publish/publish.private.pkg.spec.ts b/test/e2e-cli/test/publish/publish.private.pkg.spec.ts similarity index 86% rename from test/e2e-pkg/test/publish/publish.private.pkg.spec.ts rename to test/e2e-cli/test/publish/publish.private.pkg.spec.ts index 2c83bcbac..58611d442 100644 --- a/test/e2e-pkg/test/publish/publish.private.pkg.spec.ts +++ b/test/e2e-cli/test/publish/publish.private.pkg.spec.ts @@ -12,6 +12,10 @@ export default async function() { describe('test example', ()=> { + beforeAll(() => { + + }); + test('sub example', async () => { console.log(`New directory: ${process.cwd()}`, __dirname); process.chdir(path.join(__dirname, '../../projects/basic')); @@ -19,7 +23,7 @@ describe('test example', ()=> { await npm('install', '--registry' ,'http://localhost:4873'); // @ts-ignore - console.log('--->', global.__namespace.getItem('dir-root')); + // console.log('--->', global.__namespace.getItem('dir-root')); expect(true).toBe(true); }) }); diff --git a/test/e2e-pkg/utils/global.js b/test/e2e-cli/utils/global.js similarity index 100% rename from test/e2e-pkg/utils/global.js rename to test/e2e-cli/utils/global.js diff --git a/test/e2e-pkg/utils/process.js b/test/e2e-cli/utils/process.js similarity index 100% rename from test/e2e-pkg/utils/process.js rename to test/e2e-cli/utils/process.js diff --git a/test/e2e-pkg/setup/test_environment.ts b/test/e2e-pkg/setup/test_environment.ts deleted file mode 100644 index 60b8cbea8..000000000 --- a/test/e2e-pkg/setup/test_environment.ts +++ /dev/null @@ -1,49 +0,0 @@ -import { yellow } from 'kleur'; -const fs = require('fs'); -import os from 'os'; -import {ChildProcess, spawn} from 'child_process'; -import path from 'path'; -import NodeEnvironment from 'jest-environment-node'; -const __global = require('../utils/global'); -import { npm } from '../utils/process'; - - -class PuppeteerEnvironment extends NodeEnvironment { - private registryProcess: ChildProcess | null; - constructor(config) { - super(config) - this.registryProcess = null; - } - - async setup() { - const tempRoot = fs.mkdtempSync(path.join(fs.realpathSync(os.tmpdir()), 'verdaccio-cli-e2e-')); - __global.addItem('dir-root', tempRoot); - console.log(yellow(`Add temp root folder: ${tempRoot}`)); - fs.copyFileSync( - path.join(__dirname, '../config/_bootstrap_verdaccio.yaml'), - path.join(tempRoot, 'verdaccio.yaml'), - ); - this.global.__namespace = __global; - console.log(`current directory: ${process.cwd()}`); - console.log('resolve-->', require.resolve('verdaccio/bin/verdaccio')); - this.registryProcess = spawn( - 'node', - [require.resolve('verdaccio/bin/verdaccio'), '-c', './verdaccio.yaml'], - { cwd: tempRoot, stdio: 'inherit' }, - ); - - // publish current build version on local registry - await npm('publish', '--registry' ,'http://localhost:4873'); - } - - async teardown() { - // @ts-ignore - this.registryProcess.kill() - } - - runScript(script) { - return super.runScript(script); - } -} - -export default PuppeteerEnvironment;