Skip to content

Commit

Permalink
Simple framework for integration-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nknapp committed Mar 19, 2017
1 parent c7d8e7f commit afb708f
Show file tree
Hide file tree
Showing 8 changed files with 235 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,5 @@ npm-debug.log
.directory
._*
*.iml
/test-output/
/test/fixtures/scenarios/*/actual
2 changes: 0 additions & 2 deletions handlebars/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -254,8 +254,6 @@ module.exports = {
console.log('Cannot find repository url')
url = null
}

console.log(url.replace(''))
},

/**
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
"chai-as-promised": "^5.1.0",
"husky": "^0.12.0",
"mocha": "^2.2.5",
"recursive-copy": "^2.0.5",
"thoughtful-release": "^0.3.0"
},
"standard": {
Expand Down
55 changes: 55 additions & 0 deletions test/fixtures/scenarios/simple-project/expected/CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
## Contributing

Contributions and feedback are always welcome. The expected procedure is the following:

### Bugs, Features and Feedback

* Please, create github issues for **feature-requests**, **bug reports**.
* Feel free to open issues for **questions and problems you have**, even if they are not bugs
or feature requests.
* You may even open an issue just to say you like the project.
* For small changes, such as **typo and formatting corrections**, you can immediately
create a pull-request. You can use the github web-interface, but keep in mind that most of the documentation
is created with Thought, so you should change the template in the `.thought` directory or change the default
templates in [the thought project](https://github.com/nknapp/thought/tree/master/handlebars).
* If you have an idea for a **new feature** that you would like to implement, please **open an issue** first and ask
for feedback. Maybe someone else has a similar problem and different ideas.
* If you encounter a bug you can submit a **pull-request for a failing unit test**, you should then also open an issue
for the bug.
* Before making a pull-request, make sure that you commit corresponds to the coding-style. You can do this by
running `npm test`.

**People submitting relevant contributions will be granted commit access to the repository.**


### Coding style

[![standard][standard-image]][standard-url]

This repository uses [`standard`][standard-url] to maintain code style and consistency,
and to avoid style arguments. You can run `npm run format` to apply the coding-style, but
you may need to fix some things manually. Make sure to use the latest version of `standard`.


### Installing & Testing

You can fork and clone the repo from github. Run

* Run `npm install` to install all the dependencies needed to build and run the project.
* Run `npm test` to run unit tests and validate the `standard` coding-style.

It is intentional to don't have `standard`, `thought`, `istanbul` and `coveralls` in the devDependencies.
`standard` is a rather large package which you would not want to have copied into the `node_modules`-folder
of each of your projects.

Instead, the `pretest`- and `preformat`-scripts ensure that `standard` and `thought` are installed globally.
If you are not allowed to install packages globally, please raise an issue, so that we can try to find a solution.


### About this text

This text is part of the [Thought](https://github.com/nknapp/thought)-project. If you have any suggestions or wishes
to change the text, please raise an issue there for discussion.

[standard-image]: https://cdn.rawgit.com/feross/standard/master/badge.svg
[standard-url]: https://github.com/feross/standard
48 changes: 48 additions & 0 deletions test/fixtures/scenarios/simple-project/expected/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# simple-project

[![NPM version](https://badge.fury.io/js/simple-project.svg)](http://badge.fury.io/js/simple-project)
[![Travis Build Status](https://travis-ci.org/.svg?branch=master)](https://travis-ci.org/)
[![Coverage Status](https://img.shields.io/coveralls/.svg)](https://coveralls.io/r/)


>

# Installation

```
npm install simple-project
```


## API-reference

<a name="thought"></a>

## thought(options)
Execute Thought in the current directory

**Kind**: global function
**Api**: public

| Param | Type | Description |
| --- | --- | --- |
| options | <code>object</code> | |
| [options.cwd] | <code>string</code> | the working directory to use as project root |
| [options.addToGit] | <code>boolean</code> | add created files to git |




## License

`simple-project` is published under the ISC-license.
See []() for details.

## Release-Notes

For release notes, see [CHANGELOG.md](CHANGELOG.md)

## Contributing guidelines

See [CONTRIBUTING.md](CONTRIBUTING.md).
14 changes: 14 additions & 0 deletions test/fixtures/scenarios/simple-project/expected/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "simple-project",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"devDependencies": {
"fs-walker": "^1.0.0"
}
}
14 changes: 14 additions & 0 deletions test/fixtures/scenarios/simple-project/input/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "simple-project",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"devDependencies": {
"fs-walker": "^1.0.0"
}
}
101 changes: 101 additions & 0 deletions test/integration-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
/*!
* thought <https://github.com/nknapp/thought>
*
* Copyright (c) 2015 Nils Knappmeier.
* Released under the MIT license.
*/

/* global describe */
/* global it */
/* global before */
// /* global xdescribe */
// /* global xit */

'use strict'

var fs = require('fs')
var qfs = require('m-io/fs')
var deep = require('deep-aplus')(Promise)
var copy = require('recursive-copy')

var path = require('path')
var chai = require('chai')
var chaiAsPromised = require('chai-as-promised')
chai.use(chaiAsPromised)
var expect = chai.expect
var thought = require('../')

var basedir = path.resolve('test', 'fixtures', 'scenarios')
var scenarios = fs.readdirSync(basedir).map((name) => {
return {
name: name,
input: path.join(basedir, name, 'input'),
expected: path.join(basedir, name, 'expected'),
actual: path.join(basedir, name, 'actual'),
readExpected: function readExpected (relativePath) {
return qfs.read(path.join(this.expected, relativePath))
},
readActual: function readActual (relativePath) {
return qfs.read(path.join(this.actual, relativePath))
}
}
})

function listTreeRelative (baseDir, filter) {
return qfs.listTree(baseDir, filter)
.then((result) => {
const relativeFiles = result.map((_path) => {
return path.relative(baseDir, _path)
})
relativeFiles.sort()
return relativeFiles
})
}

function walk (baseDir, relativeDir, callback) {
var dirEntries = fs.readdirSync(path.join(baseDir, relativeDir))
dirEntries.forEach(function (fileOrDir) {
const relativePath = path.join(relativeDir, fileOrDir)
const fullPath = path.join(baseDir, relativePath)
var stats = fs.statSync(fullPath)
if (stats.isDirectory()) {
walk(baseDir, relativePath, callback)
} else if (stats.isFile()) {
callback({ relativePath })
}
})
}

describe('the integation test: ', function () {
scenarios.forEach((scenario) => {
describe(`In the scenario name "${scenario.name}",`, function () {
before(function () {
return qfs.removeTree(scenario.actual)
.then(() => copy(scenario.input, scenario.actual))
.then(() => thought({ cwd: scenario.actual }))
})

it('should have the same files as in the output', function () {
var filter = (name, stats) => stats.isFile()
var expected = listTreeRelative(scenario.expected, filter)
var actual = listTreeRelative(scenario.actual, filter)
return deep({ expected, actual })
.then(function (result) {
console.log(result)
expect(result.actual).to.deep.equal(result.expected)
})
})

walk(scenario.expected, '', function (file) {
it(`the file "${file.relativePath}" should match`, function () {
var expectedContents = scenario.readExpected(file.relativePath)
var actualContents = scenario.readActual(file.relativePath)
return deep({expectedContents, actualContents})
.then((result) => expect(result.actualContents).to.equal(result.expectedContents)
)
})
})
})
})
})

0 comments on commit afb708f

Please sign in to comment.