Skip to content

Commit

Permalink
Fix engines 1373 (#1375)
Browse files Browse the repository at this point in the history
* fix: use engines from CLI package, close #1373

* chore: add integration test for build script that writes package.json file

* do not hardcode version

* build npm package in this branch too
  • Loading branch information
bahmutov authored and brian-mann committed Feb 26, 2018
1 parent d7dddc1 commit cf07e21
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 19 deletions.
3 changes: 3 additions & 0 deletions circle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -711,20 +711,23 @@ workflows:
branches:
only:
- develop
- fix-engines-1373
requires:
- build
- build-binary:
filters:
branches:
only:
- develop
- fix-engines-1373
requires:
- build
- test-next-version:
filters:
branches:
only:
- develop
- fix-engines-1373
requires:
- build-npm-package
- build-binary
Expand Down
21 changes: 21 additions & 0 deletions cli/__snapshots__/build_spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
exports['package.json build outputs expected properties 1'] = {
"name": "test",
"engines": "test engines",
"version": "x.y.z",
"description": "Cypress.io end to end testing tool",
"author": "Brian Mann",
"homepage": "https://github.com/cypress-io/cypress",
"license": "MIT",
"bugs": {
"url": "https://github.com/cypress-io/cypress/issues"
},
"repository": {
"type": "git",
"url": "https://github.com/cypress-io/cypress.git"
},
"types": "types",
"scripts": {
"postinstall": "node index.js --exec install",
"size": "t=\"$(npm pack .)\"; wc -c \"${t}\"; tar tvf \"${t}\"; rm \"${t}\";"
}
}
33 changes: 24 additions & 9 deletions cli/scripts/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ const path = require('path')

const fs = require('../lib/fs')

// grab the current version from the root monorepo package.json
// grab the current version and a few other properties
// from the root package.json
const {
version,
description,
Expand All @@ -12,9 +13,9 @@ const {
license,
bugs,
repository,
engines,
} = require('@packages/root')

// the rest of properties should come from the package.json in CLI folder
const packageJsonSrc = path.join('package.json')
const packageJsonDest = path.join('build', 'package.json')

Expand All @@ -32,7 +33,6 @@ function preparePackageForNpmRelease (json) {
license,
bugs,
repository,
engines,
types: 'types', // typescript types
scripts: {
postinstall: 'node index.js --exec install',
Expand All @@ -43,10 +43,25 @@ function preparePackageForNpmRelease (json) {
return json
}

fs.readJsonAsync(packageJsonSrc)
.then(preparePackageForNpmRelease)
.then((json) => {
return fs.outputJsonAsync(packageJsonDest, json, {
spaces: 2,
function makeUserPackageFile () {
return fs.readJsonAsync(packageJsonSrc)
.then(preparePackageForNpmRelease)
.then((json) => {
return fs.outputJsonAsync(packageJsonDest, json, {
spaces: 2,
}).then(() => json) // returning package json object makes it easy to test
})
})
}

module.exports = makeUserPackageFile

if (!module.parent) {
makeUserPackageFile()
.catch((err) => {
/* eslint-disable no-console */
console.error('Could not write user package file')
console.error(err)
/* eslint-enable no-console */
process.exit(-1)
})
}
41 changes: 41 additions & 0 deletions cli/test/lib/build_spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
require('../spec_helper')

const fs = require(`${lib}/fs`)
const makeUserPackageFile = require('../../scripts/build')
const snapshot = require('snap-shot-it')
const la = require('lazy-ass')
const is = require('check-more-types')
const R = require('ramda')

const hasVersion = (json) =>
la(is.semver(json.version), 'cannot find version', json)

const hasAuthor = (json) =>
la(json.author === 'Brian Mann', 'wrong author name', json)

const changeVersion = R.assoc('version', 'x.y.z')

describe('package.json build', () => {
beforeEach(function () {
// stub package.json in CLI
// with a few test props
// the rest should come from root package.json file
this.sandbox.stub(fs, 'readJsonAsync').resolves({
name: 'test',
engines: 'test engines',
})
this.sandbox.stub(fs, 'outputJsonAsync').resolves()
})

it('author name and version', () => {
return makeUserPackageFile()
.tap(hasAuthor)
.tap(hasVersion)
})

it('outputs expected properties', () => {
return makeUserPackageFile()
.then(changeVersion)
.then(snapshot)
})
})
20 changes: 10 additions & 10 deletions cli/test/lib/cypress_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ describe('cypress', function () {

it('calls run#start, passing in options', () =>
cypress.run({ foo: 'foo' })
.then(getStartArgs)
.then((args) => {
expect(args.foo).to.equal('foo')
})
.then(getStartArgs)
.then((args) => {
expect(args.foo).to.equal('foo')
})
)

it('normalizes config object', () => {
Expand All @@ -58,20 +58,20 @@ describe('cypress', function () {
watchForFileChanges: false,
}
return cypress.run({ config })
.then(getStartArgs)
.then(snapshot)
.then(getStartArgs)
.then(snapshot)
})

it('normalizes env option if passed an object', () =>
cypress.run({ env: { foo: 'bar' } })
.then(getStartArgs)
.then(snapshot)
.then(getStartArgs)
.then(snapshot)
)

it('normalizes env option if passed an object with multiple properties', () =>
cypress.run({ env: { foo: 'bar', another: 'one' } })
.then(getStartArgs)
.then(snapshot)
.then(getStartArgs)
.then(snapshot)
)

it('gets random tmp file and passes it to run#start', function () {
Expand Down

0 comments on commit cf07e21

Please sign in to comment.