Skip to content
This repository has been archived by the owner on Feb 18, 2024. It is now read-only.

Commit

Permalink
Use verdaccio to test create-project (#877)
Browse files Browse the repository at this point in the history
* Use verdaccio to test create-project

* Review revisions

* Trying to automate publish

* Move environment var to create-project script

* Set yarn auth token in env

* Set fake token against localhost

* Publish major version in testing

* Remove extra deps, unused script, incorrect test file assertion

* Document verdaccio script and test commands
  • Loading branch information
eliperelman authored May 17, 2018
1 parent 7b9b391 commit ef553a9
Show file tree
Hide file tree
Showing 12 changed files with 554 additions and 272 deletions.
7 changes: 5 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ node_modules
# Optional REPL history
.node_repl_history

# Webstorm project metadata
# Project metadata
.idea

/.vscode

# Verdaccio
storage
htpasswd
5 changes: 2 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@ install:
# Remove --ignore-engines when this fixed:
# https://github.com/anodynos/upath/issues/14
- yarn install --frozen-lockfile --ignore-engines
- yarn link:all
script:
- yarn validate:eslintrc
- yarn lint
- yarn build
- yarn test:all
- yarn test
- scripts/test-create-project-ci.sh
27 changes: 27 additions & 0 deletions docs/contributing/development.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,33 @@ anywhere on your system for neutrino-dev packages, making testing of the package

---

`test`

Runs the unit test suite against all packages in the monorepo. For the most part
the intent of the unit tests is to ensure that packages do not throw errors
when being required or used as middleware by Neutrino. These tests typically
do not ensure that their middleware produces the expected output, instead
leaving this functionality for integration tests via `test:create-project`.

---

`test:create-project`

Runs the integration test suite by determining correct output of the
`create-project` CLI tool and ensuring that package.json scripts do not throw.
This test requires a local [verdaccio](https://www.verdaccio.org/) instance
to be running, and this is ensured in CI via the
`scripts/test-create-project-ci.sh` script. Typically this command is only used
in CI, with the unit tests being run locally via `yarn test`. If you do run
this command locally by setting up verdaccio locally as well, ensure that
you revert back any changes you make to your local registry when finished with:

```bash
yarn config set registry https://registry.yarnpkg.com
```

---

`changelog`

Generates a changelog for the `mozilla-neutrino/neutrino-dev` GitHub repository. This changelog is output to a
Expand Down
16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,22 @@
"packages/*"
],
"scripts": {
"build": "lerna run build",
"changelog": "auto-changelog --remote upstream --commit-limit false",
"cnp": "NODE_ENV=test packages/create-project/bin/create-neutrino-project.js $(yarn random)",
"link:all": "lerna exec yarn link",
"lint": "node packages/neutrino/bin/neutrino lint",
"precommit": "lint-staged",
"random": "node -e \"process.stdout.write(require('crypto').randomBytes(8).toString('hex'))\"",
"release": "yarn build && lerna publish --force-publish=*",
"release:preview": "yarn build && lerna publish --force-publish=* --skip-git --skip-npm",
"test": "yarn test:all --no-verbose --match '!*@neutrinojs*'",
"test:all": "nyc --reporter lcov ava --verbose --fail-fast packages/*/test",
"release": "lerna publish --force-publish=*",
"release:preview": "lerna publish --force-publish=* --skip-git --skip-npm",
"test": "ava --fail-fast packages/*/test \"!packages/create-project/test\"",
"test:create-project": "ava --verbose packages/create-project/test",
"validate:eslintrc:root": "eslint --no-eslintrc --print-config . -c ./.eslintrc.js > /dev/null",
"validate:eslintrc:eslint": "eslint --no-eslintrc --print-config . -c ./packages/eslint/eslintrc.js > /dev/null",
"validate:eslintrc:airbnb": "eslint --no-eslintrc --print-config . -c ./packages/airbnb/eslintrc.js > /dev/null",
"validate:eslintrc:airbnb-base": "eslint --no-eslintrc --print-config . -c ./packages/airbnb-base/eslintrc.js > /dev/null",
"validate:eslintrc:standardjs": "eslint --no-eslintrc --print-config . -c ./packages/standardjs/eslintrc.js > /dev/null",
"validate:eslintrc": "yarn validate:eslintrc:eslint && yarn validate:eslintrc:airbnb-base && yarn validate:eslintrc:airbnb && yarn validate:eslintrc:standardjs && yarn validate:eslintrc:root",
"version": "yarn changelog --package && git add CHANGELOG.md"
"version": "test -v SKIP_CHANGELOG || yarn changelog --package && git add CHANGELOG.md"
},
"devDependencies": {
"auto-changelog": "^1.4.6",
Expand All @@ -44,7 +42,9 @@
"lerna": "^2.11.0",
"lint-staged": "^7.0.5",
"nyc": "^11.7.1",
"prettier": "^1.12.1"
"prettier": "^1.12.1",
"verdaccio": "3.0.0-beta.10",
"verdaccio-memory": "^1.0.1"
},
"lint-staged": {
"*.js": [
Expand Down
72 changes: 38 additions & 34 deletions packages/create-project/commands/init/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ const { basename, join, relative } = require('path');
const chalk = require('chalk');
const stringify = require('javascript-stringify');
const merge = require('deepmerge');
const { contains, partition } = require('ramda');
const Generator = require('yeoman-generator');
const questions = require('./questions');
const { projects, packages, isYarn } = require('./utils');
Expand Down Expand Up @@ -145,42 +144,45 @@ module.exports = class Project extends Generator {

if (dependencies) {
this.log(`${chalk.green('⏳ Installing dependencies:')} ${chalk.yellow(dependencies.join(', '))}`);
this.spawnCommandSync(packageManager, [install, ...dependencies], {
cwd: this.options.directory,
stdio: this.options.stdio,
env: process.env
});
this.spawnCommandSync(
packageManager,
[
install,
...(
this.options.registry
? ['--registry', this.options.registry] :
[]
),
...dependencies
],
{
cwd: this.options.directory,
stdio: this.options.stdio,
env: process.env
}
);
}

if (devDependencies) {
if (process.env.NODE_ENV === 'test') {
const [local, remote] = partition(contains(packages.NEUTRINO), devDependencies);

if (remote.length) {
this.log(`${chalk.green('⏳ Installing remote devDependencies:')} ${chalk.yellow(remote.join(', '))}`);
this.spawnCommandSync(packageManager, [install, devFlag, ...remote], {
stdio: this.options.stdio,
env: process.env,
cwd: this.options.directory
});
}

if (local.length) {
this.log(`${chalk.green('⏳ Linking local devDependencies:')} ${chalk.yellow(local.join(', '))}`);
this.spawnCommandSync('yarn', ['link', ...local], {
stdio: this.options.stdio,
env: process.env,
cwd: this.options.directory
});
}
} else {
this.log(`${chalk.green('⏳ Installing devDependencies:')} ${chalk.yellow(devDependencies.join(', '))}`);
this.spawnCommandSync(packageManager, [install, devFlag, ...devDependencies], {
this.log(`${chalk.green('⏳ Installing devDependencies:')} ${chalk.yellow(devDependencies.join(', '))}`);
this.spawnCommandSync(
packageManager,
[
install,
devFlag,
...(
this.options.registry
? ['--registry', this.options.registry] :
[]
),
...devDependencies
],
{
cwd: this.options.directory,
stdio: this.options.stdio,
env: process.env,
cwd: this.options.directory
});
}
env: process.env
}
);
}

if (this.data.linter) {
Expand All @@ -190,7 +192,9 @@ module.exports = class Project extends Generator {
? ['lint', '--fix']
: ['run', 'lint', '--fix'],
{
stdio: this.options.stdio === 'inherit' ? 'ignore' : this.options.stdio,
stdio: this.options.stdio === 'inherit' || !this.options.stdio
? 'ignore' :
this.options.stdio,
env: process.env,
cwd: this.options.directory
});
Expand Down
94 changes: 94 additions & 0 deletions packages/create-project/commands/init/matrix.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
const LINTING = 'linting';
const PROJECT = 'project';
const TESTING = 'testing';
const N = 'neutrino';
const REACT = '@neutrinojs/react';
const PREACT = '@neutrinojs/preact';
const VUE = '@neutrinojs/vue';
const WEB = '@neutrinojs/web';
const NODE = '@neutrinojs/node';
const WEB_NODE_LIBRARY = '@neutrinojs/library';
const REACT_COMPONENTS = '@neutrinojs/react-components';
const JEST = '@neutrinojs/jest';
const KARMA = '@neutrinojs/karma';
const MOCHA = '@neutrinojs/mocha';
const AIRBNB = '@neutrinojs/airbnb';
const AIRBNB_BASE = '@neutrinojs/airbnb-base';
const STANDARDJS = '@neutrinojs/standardjs';

const projects = {
[AIRBNB]: {
type: LINTING,
devDependencies: [AIRBNB]
},
[AIRBNB_BASE]: {
type: LINTING,
devDependencies: [AIRBNB_BASE]
},
[WEB_NODE_LIBRARY]: {
type: PROJECT,
devDependencies: [WEB_NODE_LIBRARY, N]
},
[NODE]: {
type: PROJECT,
devDependencies: [NODE, N]
},
[PREACT]: {
type: PROJECT,
dependencies: ['preact', 'preact-compat'],
devDependencies: [PREACT, N]
},
[REACT]: {
type: PROJECT,
dependencies: ['prop-types', 'react', 'react-dom', 'react-hot-loader'],
devDependencies: [REACT, N]
},
[REACT_COMPONENTS]: {
type: PROJECT,
devDependencies: [REACT_COMPONENTS, N, 'prop-types', 'react', 'react-dom']
},
[STANDARDJS]: {
type: LINTING,
devDependencies: [STANDARDJS]
},
[VUE]: {
type: PROJECT,
dependencies: ['vue'],
devDependencies: [VUE, N]
},
[WEB]: {
type: PROJECT,
devDependencies: [WEB, N]
},
[JEST]: {
type: TESTING,
devDependencies: [JEST]
},
[KARMA]: {
type: TESTING,
devDependencies: [KARMA]
},
[MOCHA]: {
type: TESTING,
devDependencies: [MOCHA]
}
};

const packages = {
NEUTRINO: N,
REACT,
PREACT,
VUE,
WEB,
NODE,
WEB_NODE_LIBRARY,
REACT_COMPONENTS,
JEST,
KARMA,
MOCHA,
AIRBNB,
AIRBNB_BASE,
STANDARDJS
};

module.exports = { projects, packages };
94 changes: 1 addition & 93 deletions packages/create-project/commands/init/utils.js
Original file line number Diff line number Diff line change
@@ -1,97 +1,5 @@
const commandExists = require('command-exists');

const LINTING = 'linting';
const PROJECT = 'project';
const TESTING = 'testing';
const N = 'neutrino';
const REACT = '@neutrinojs/react';
const PREACT = '@neutrinojs/preact';
const VUE = '@neutrinojs/vue';
const WEB = '@neutrinojs/web';
const NODE = '@neutrinojs/node';
const WEB_NODE_LIBRARY = '@neutrinojs/library';
const REACT_COMPONENTS = '@neutrinojs/react-components';
const JEST = '@neutrinojs/jest';
const KARMA = '@neutrinojs/karma';
const MOCHA = '@neutrinojs/mocha';
const AIRBNB = '@neutrinojs/airbnb';
const AIRBNB_BASE = '@neutrinojs/airbnb-base';
const STANDARDJS = '@neutrinojs/standardjs';

const projects = {
[AIRBNB]: {
type: LINTING,
devDependencies: [AIRBNB]
},
[AIRBNB_BASE]: {
type: LINTING,
devDependencies: [AIRBNB_BASE]
},
[WEB_NODE_LIBRARY]: {
type: PROJECT,
devDependencies: [WEB_NODE_LIBRARY, N]
},
[NODE]: {
type: PROJECT,
devDependencies: [NODE, N]
},
[PREACT]: {
type: PROJECT,
dependencies: ['preact', 'preact-compat'],
devDependencies: [PREACT, N]
},
[REACT]: {
type: PROJECT,
dependencies: ['prop-types', 'react', 'react-dom', 'react-hot-loader'],
devDependencies: [REACT, N]
},
[REACT_COMPONENTS]: {
type: PROJECT,
devDependencies: [REACT_COMPONENTS, N, 'prop-types', 'react', 'react-dom']
},
[STANDARDJS]: {
type: LINTING,
devDependencies: [STANDARDJS]
},
[VUE]: {
type: PROJECT,
dependencies: ['vue'],
devDependencies: [VUE, N]
},
[WEB]: {
type: PROJECT,
devDependencies: [WEB, N]
},
[JEST]: {
type: TESTING,
devDependencies: [JEST]
},
[KARMA]: {
type: TESTING,
devDependencies: [KARMA]
},
[MOCHA]: {
type: TESTING,
devDependencies: [MOCHA]
}
};

const packages = {
NEUTRINO: N,
REACT,
PREACT,
VUE,
WEB,
NODE,
WEB_NODE_LIBRARY,
REACT_COMPONENTS,
JEST,
KARMA,
MOCHA,
AIRBNB,
AIRBNB_BASE,
STANDARDJS
};
const { packages, projects } = require('./matrix');

const isYarn = commandExists.sync('yarnpkg');

Expand Down
1 change: 0 additions & 1 deletion packages/create-project/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
"deepmerge": "^1.5.2",
"fs-extra": "^6.0.0",
"javascript-stringify": "^1.6.0",
"ramda": "^0.25.0",
"yargs": "^11.0.0",
"yeoman-environment": "^2.0.6",
"yeoman-generator": "^2.0.5"
Expand Down
Loading

0 comments on commit ef553a9

Please sign in to comment.