Skip to content

ci: running some test cases with a local registry to better reflect real-world use cases #4193

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 20 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 31 additions & 18 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,19 @@ jobs:
steps:
- attach_workspace:
at: ~/
- run: yarn test -p unit-mocha,unit-jest,e2e-cypress
- run: yarn test -p unit-mocha,e2e-cypress
# e2e-nightwatch was left out due to some unknown issues with selenium and the CI image
- run: yarn test tsPluginE2e

tests-after-publish:
<<: *defaults
steps:
- attach_workspace:
at: ~/
- run: mkdir ../tests
- run: ./scripts/local-registry.sh
- run: yarn test -p unit-jest

cli-ui:
<<: *defaults
steps:
Expand All @@ -80,23 +89,27 @@ workflows:
jobs:
- install:
<<: *filters
- group-1:
<<: *filters
requires:
- install
- group-2:
<<: *filters
requires:
- install
- group-3:
<<: *filters
requires:
- install
- group-4:
<<: *filters
requires:
- install
- cli-ui:
# - group-1:
# <<: *filters
# requires:
# - install
# - group-2:
# <<: *filters
# requires:
# - install
# - group-3:
# <<: *filters
# requires:
# - install
# - group-4:
# <<: *filters
# requires:
# - install
- tests-after-publish:
<<: *filters
requires:
- install
# - cli-ui:
# <<: *filters
# requires:
# - install
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
jest.setTimeout(30000)
jest.setTimeout(300000)

const fs = require('fs-extra')
const path = require('path')
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
jest.setTimeout(30000)
jest.setTimeout(300000)

const Service = require('@vue/cli-service/lib/Service')
const { assertServe, assertBuild } = require('./tsPlugin.helper')
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
jest.setTimeout(30000)
jest.setTimeout(300000)

const { assertServe, assertBuild } = require('./tsPlugin.helper')

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
jest.setTimeout(30000)
jest.setTimeout(300000)

const { assertServe, assertBuild } = require('./tsPlugin.helper')

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
jest.setTimeout(30000)
jest.setTimeout(300000)

const create = require('@vue/cli-test-utils/createTestProject')

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
jest.setTimeout(20000)
jest.setTimeout(200000)

const create = require('@vue/cli-test-utils/createTestProject')

Expand Down
2 changes: 1 addition & 1 deletion packages/@vue/cli-service/__tests__/build.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
jest.setTimeout(30000)
jest.setTimeout(300000)

const path = require('path')
const portfinder = require('portfinder')
Expand Down
2 changes: 1 addition & 1 deletion packages/@vue/cli-service/__tests__/buildWc.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
jest.setTimeout(30000)
jest.setTimeout(300000)

const path = require('path')
const portfinder = require('portfinder')
Expand Down
2 changes: 1 addition & 1 deletion packages/@vue/cli-service/__tests__/cors.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
jest.setTimeout(30000)
jest.setTimeout(300000)

const path = require('path')
const portfinder = require('portfinder')
Expand Down
2 changes: 1 addition & 1 deletion packages/@vue/cli-service/__tests__/proxy.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
jest.setTimeout(30000)
jest.setTimeout(300000)

const request = require('request-promise-native')
const { defaultPreset } = require('@vue/cli/lib/options')
Expand Down
7 changes: 6 additions & 1 deletion packages/@vue/cli-test-utils/createTestProject.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@ const execa = require('execa')
module.exports = function createTestProject (name, preset, cwd, initGit) {
delete process.env.VUE_CLI_SKIP_WRITE

cwd = cwd || path.resolve(__dirname, '../../test')
if (!cwd) {
cwd = path.resolve(__dirname, '../../../../test')
if (!fs.existsSync(cwd)) {
fs.mkdirSync(cwd)
}
}

const projectRoot = path.resolve(cwd, name)

Expand Down
18 changes: 9 additions & 9 deletions packages/@vue/cli/lib/Creator.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,12 +155,12 @@ module.exports = class Creator extends EventEmitter {
log(`⚙ Installing CLI plugins. This might take a while...`)
log()
this.emit('creation', { event: 'plugins-install' })
if (isTestOrDebug) {
// in development, avoid installation process
await require('./util/setupDevProject')(context)
} else {
await installDeps(context, packageManager, cliOptions.registry)
}
// if (isTestOrDebug) {
// // in development, avoid installation process
// await require('./util/setupDevProject')(context)
// } else {
await installDeps(context, packageManager, cliOptions.registry)
// }

// run generator
log(`🚀 Invoking generators...`)
Expand All @@ -179,9 +179,9 @@ module.exports = class Creator extends EventEmitter {
log(`📦 Installing additional dependencies...`)
this.emit('creation', { event: 'deps-install' })
log()
if (!isTestOrDebug) {
await installDeps(context, packageManager, cliOptions.registry)
}
// if (!isTestOrDebug) {
await installDeps(context, packageManager, cliOptions.registry)
// }

// run complete cbs if any (injected by generators)
logWithSpinner('⚓', `Running completion hooks...`)
Expand Down
4 changes: 2 additions & 2 deletions packages/@vue/cli/lib/invoke.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ async function invoke (pluginName, options = {}, context = process.cwd()) {
}

async function runGenerator (context, plugin, pkg = getPkg(context)) {
const isTestOrDebug = process.env.VUE_CLI_TEST || process.env.VUE_CLI_DEBUG
// const isTestOrDebug = process.env.VUE_CLI_TEST || process.env.VUE_CLI_DEBUG
const createCompleteCbs = []
const generator = new Generator(context, {
pkg,
Expand All @@ -141,7 +141,7 @@ async function runGenerator (context, plugin, pkg = getPkg(context)) {
JSON.stringify(newDeps) !== JSON.stringify(pkg.dependencies) ||
JSON.stringify(newDevDeps) !== JSON.stringify(pkg.devDependencies)

if (!isTestOrDebug && depsChanged) {
if (depsChanged) {
log(`📦 Installing additional dependencies...`)
log()
const packageManager =
Expand Down
7 changes: 6 additions & 1 deletion packages/@vue/cli/lib/util/installDeps.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,14 @@ function executeCommand (command, args, targetDir) {
}
}

const stdio = ['inherit', apiMode ? 'pipe' : 'inherit', !apiMode && command === 'yarn' ? 'pipe' : 'inherit']
if (process.env.VUE_CLI_TEST) {
stdio[0] = stdio[1] = 'ignore'
}

const child = execa(command, args, {
cwd: targetDir,
stdio: ['inherit', apiMode ? 'pipe' : 'inherit', !apiMode && command === 'yarn' ? 'pipe' : 'inherit']
stdio
})

if (apiMode) {
Expand Down
53 changes: 53 additions & 0 deletions scripts/local-registry.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/bin/bash

# adapted from https://github.com/facebook/create-react-app/blob/master/tasks/local-registry.sh

custom_registry_url=http://localhost:4873
original_npm_registry_url=`npm get registry`
original_yarn_registry_url=`yarn config get registry`
default_verdaccio_package=verdaccio@3

function startLocalRegistry {
# Start local registry
tmp_registry_log=`mktemp`
echo "Registry output file: $tmp_registry_log"
(cd && nohup npx $default_verdaccio_package -c ${CIRCLE_WORKING_DIRECTORY}/scripts/verdaccio.yaml &>$tmp_registry_log &)
# Wait for Verdaccio to boot
grep -q 'http address' <(tail -f $tmp_registry_log)

# Set registry to local registry
npm set registry "$custom_registry_url"
yarn config set registry "$custom_registry_url"

echo "set registry done"

# set git user
git config --global user.email "user@example.com"
git config --global user.name "user"

echo "git config done"

git config --get user.email

# Login so we can publish packages
(cd && npx npm-auth-to-token@1 -u user -p password -e user@example.com -r "$custom_registry_url")

echo "npm user auth done"
}

function stopLocalRegistry {
# Restore the original NPM and Yarn registry URLs and stop Verdaccio
npm set registry "$original_npm_registry_url"
yarn config set registry "$original_yarn_registry_url"

# Kill Verdaccio process
ps -ef | grep 'verdaccio' | grep -v grep | awk '{print $2}' | xargs kill -9
}

function publishToLocalRegistry {
git clean -df
yarn release --local-registry
}

startLocalRegistry
publishToLocalRegistry
15 changes: 14 additions & 1 deletion scripts/release.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,18 @@ process.env.VUE_CLI_RELEASE = true
const execa = require('execa')
const semver = require('semver')
const inquirer = require('inquirer')
const minimist = require('minimist')
const { syncDeps } = require('./syncDeps')
// const { buildEditorConfig } = require('./buildEditorConfig')

const cliOptions = minimist(process.argv)
if (cliOptions['local-registry']) {
inquirer.prompt = () => ({
bump: 'minor',
yes: true
})
}

const curVersion = require('../lerna.json').version

const release = async () => {
Expand Down Expand Up @@ -96,7 +105,7 @@ const release = async () => {
const releaseType = semver.diff(curVersion, version)

let distTag = 'latest'
if (releaseType.startsWith('pre')) {
if (releaseType.startsWith('pre') && !cliOptions['local-registry']) {
distTag = 'next'
}

Expand All @@ -111,6 +120,10 @@ const release = async () => {
lernaArgs.push('--force-publish')
}

if (cliOptions['local-registry']) {
lernaArgs.push('--no-git-tag-version', '--no-commit-hooks', '--no-push', '--yes')
}

await execa(require.resolve('lerna/cli'), lernaArgs, { stdio: 'inherit' })
}

Expand Down
60 changes: 60 additions & 0 deletions scripts/verdaccio.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#
# This is based on verdaccio's default config file. It allows all users
# to do anything, so don't use it on production systems.
#
# Look here for more config file examples:
# https://github.com/verdaccio/verdaccio/tree/master/conf
#

# path to a directory with all packages
storage: ./storage

auth:
htpasswd:
file: ./htpasswd
# Maximum amount of users allowed to register, defaults to "+inf".
# You can set this to -1 to disable registration.
#max_users: 1000

# a list of other known repositories we can talk to
uplinks:
npmjs:
url: https://registry.npmjs.org/
max_fails: 40
maxage: 30m
timeout: 60s
agent_options:
keepAlive: true
maxSockets: 40
maxFreeSockets: 10

packages:
'@*/*':
# scoped packages
access: $all
publish: $all
proxy: npmjs

'**':
# allow all users (including non-authenticated users) to read and
# publish all packages
#
# you can specify usernames/groupnames (depending on your auth plugin)
# and three keywords: "$all", "$anonymous", "$authenticated"
access: $all

# allow all known users to publish packages
# (anyone can register by default, remember?)
publish: $all

# if package is not available locally, proxy requests to 'npmjs' registry
proxy: npmjs

# log settings
logs:
- {type: stdout, format: pretty, level: warn}
#- {type: file, path: verdaccio.log, level: info}

# See https://github.com/verdaccio/verdaccio/issues/301
server:
keepAliveTimeout: 0