Skip to content

Commit

Permalink
Merge pull request #1 from snyk/test/adding-tests
Browse files Browse the repository at this point in the history
test: adding system and functional tests
  • Loading branch information
deebugger committed Jun 21, 2017
2 parents 37d8aa7 + 4d07743 commit 838302d
Show file tree
Hide file tree
Showing 15 changed files with 168 additions and 36 deletions.
45 changes: 45 additions & 0 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Contributing

## Commit messages

Commit messages must follow the [Angular-style](https://github.com/angular/angular.js/blob/master/CONTRIBUTING.md#commit-message-format) commit format (but excluding the scope).

i.e:

```text
fix: minified scripts being removed
Also includes tests
```

This will allow for the automatic changelog to generate correctly.

### Commit types

Must be one of the following:

* **feat**: A new feature
* **fix**: A bug fix
* **docs**: Documentation only changes
* **test**: Adding missing tests
* **chore**: Changes to the build process or auxiliary tools and libraries such as documentation generation
* **refactor**: A code change that neither fixes a bug nor adds a feature
* **style**: Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc)
* **perf**: A code change that improves performance

To release a major you need to add `BREAKING CHANGE: ` to the start of the body and the detail of the breaking change.

## Code standards

Ensure that your code adheres to the included `.jshintrc` and `.jscsrc` configs.

## Sending pull requests

- new command line options are generally discouraged unless there's a *really* good reason
- add tests for newly added code (and try to mirror directory and file structure if possible)
- spell check
- PRs will not be code reviewed unless all tests are passing

*Important:* when fixing a bug, please commit a **failing test** first so that Travis CI (or I can) can show the code failing. Once that commit is in place, then commit the bug fix, so that we can test *before* and *after*.

Remember that you're developing for multiple platforms and versions of node, so if the tests pass on your Mac or Linux or Windows machine, it *may* not pass elsewhere.
17 changes: 17 additions & 0 deletions .github/ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
- `node -v`:
- `npm -v`:
- `snyk -v`:
- Command run:

### Expected behaviour


### Actual behaviour


### Steps to reproduce


---

If applicable, please append the `--debug` flag on your command and include the output here **ensuring to remove any sensitive/personal details or tokens.
23 changes: 23 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
- [ ] Ready for review
- [ ] Follows CONTRIBUTING rules
- [ ] Reviewed by Snyk internal team

#### What does this PR do?


#### Where should the reviewer start?


#### How should this be manually tested?


#### Any background context you want to provide?


#### What are the relevant tickets?


#### Screenshots


#### Additional questions
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/node_modules/
__pycache__/
*.pyc
test/fixtures/testproj/project/project/
test/fixtures/testproj/project/target/
test/fixtures/testproj/target/
9 changes: 1 addition & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,15 @@ node_js:
- "8"
- "6"
- "4"
- "0.12"
cache:
directories:
- node_modules
before_script:
- export PATH=$HOME/.local/bin:$PATH
- pip install virtualenv --user `whoami`
- virtualenv ./env
- source ./env/bin/activate
script: npm test
script: npm run test
jobs:
include:
- stage: npm release
node_js: "8" # This *has* to be the "build leader"
script: skip
before_script: # Don't need virtualenv for release, so skip it
after_success:
- TRAVIS_JOB_NUMBER=WORKAROUND.1 npm run semantic-release
branches:
Expand Down
1 change: 1 addition & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ module.exports = {
};

function inspect(root, targetFile, options) {
if (!options) { options = { dev: false }; }
return subProcess.execute('sbt',
buildArgs(root, targetFile, options.args),
{ cwd: root })
Expand Down
48 changes: 26 additions & 22 deletions lib/parse-sbt.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,33 @@
var tabdown = require('./tabdown');

function converStrToTree(dependenciesTextTree) {
var lines = dependenciesTextTree.toString().split('\n');
var newLines = [];
for (var i = 0; i < lines.length; i++) {
if (lines[i].indexOf('+-') > -1 ||
i + 1 !== lines.length &&
lines[i + 1].indexOf('+-') > -1 &&
lines[i].length > 10) {
var line = lines[i];
if (line.indexOf('|') > -1) {
line = line.slice(line.indexOf('|'), line.length);
} else if (line.indexOf('+-') > -1) {
line = line.slice(line.indexOf('+-'), line.length);
}
line = line.split('|').join(' \t');
line = line.split('+-').join(' \t');
line = line.split('\u001b[0m').join('');
line = line.split('[info]').join('');
line = line.split(' [S]').join('');
line = line.split('[]').join('');
line = line.split(' ').join(' \t');
newLines.push(line);
var lines = dependenciesTextTree.toString().split('\n') || [];
var newLines = dependenciesTextTree.toString().split('\n')
.map(function (line) {
return line.replace(/\u001b\[0m/g, '');
})
.filter(function (line) {
if (line.indexOf('[info] ') === 0 && line.indexOf('+-') > -1) {
return true;
}
}
var match = line.match(/\[info\]\s[\w_\.\-]+:[\w_\.\-]+:[\w_\.\-]+/);
if (match && match[0].length === line.length) {
return true;
}
match = line.match(/\[info\]\s[\w_\.\-]+:[\w_\.\-]+:[\w_\.\-]+\s\[S\]/);
if (match && match[0].length === line.length) {
return true;
}
return false;
})
.map(function (line) {
return line
.slice(7, line.length) // slice off '[info] '
.replace(' [S]', '')
.replace(/\|/g, ' ')
.replace('+-', '')
.replace(/\s\s/g, '\t');
});
var tree = tabdown.parse(newLines, '\t');
return tree;
}
Expand Down
1 change: 0 additions & 1 deletion lib/sub-process.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
var Promise = require('es6-promise').Promise;
var childProcess = require('child_process');

module.exports.execute = function (command, args, options) {
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
},
"main": "lib/index.js",
"scripts": {
"test": "tap `find ./test -name '*.test.js'`",
"test": "npm run lint && npm run test-functional",
"lint": "jscs `find ./lib -name '*.js'` -v && jscs `find ./test -name '*.js'` -v",
"test-functional": "tap `find ./test/functional -name '*.test.js'`",
"test-system": "tap `find ./test/system -name '*.test.js'`",
"semantic-release": "semantic-release pre && npm publish && semantic-release post"
},
"author": "snyk.io",
Expand Down
10 changes: 10 additions & 0 deletions test/fixtures/testproj/build.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
lazy val root = (project in file(".")).
settings(
inThisBuild(List(
organization := "com.example",
scalaVersion := "2.12.1",
version := "0.1.0-SNAPSHOT"
)),
name := "Hello",
libraryDependencies += "axis" % "axis" % "1.4"
)
1 change: 1 addition & 0 deletions test/fixtures/testproj/project/build.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sbt.version=0.13.13
1 change: 1 addition & 0 deletions test/fixtures/testproj/project/site.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
addSbtPlugin("net.virtual-void" % "sbt-dependency-graph" % "0.8.2")
9 changes: 9 additions & 0 deletions test/fixtures/testproj/src/main/scala/example/Hello.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package example

object Hello extends Greeting with App {
println(greeting)
}

trait Greeting {
lazy val greeting: String = "hello"
}
13 changes: 9 additions & 4 deletions test/parse-sbt.test.js → test/functional/parse-sbt.test.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
var test = require('tap-only');
var parse = require('../lib/parse-sbt');
var parse = require('../../lib/parse-sbt');
var fs = require('fs');

test('parse a `sbt dependencies` output', function(t) {
t.plan(3);
test('parse a `sbt dependencies` output', function (t) {
t.plan(4);
var sbtOutput = fs.readFileSync(
__dirname + '/fixtures/sbt-dependency-output.txt', 'utf8');
__dirname + '/../fixtures/sbt-dependency-output.txt', 'utf8');
var depTree = parse(sbtOutput, 'testApp', '1.0.1');

t.equal(depTree
.dependencies['myproject-common:myproject-common_2.11']
.version,
'0.0.1', 'resolved stand-alone dependency');

t.equal(depTree
.dependencies['myproject-api:myproject-api_2.11']
.dependencies['org.slf4j:slf4j-nop'].version,
Expand Down
19 changes: 19 additions & 0 deletions test/system/plugin.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
var test = require('tap-only');
var plugin = require('../../lib');
var fs = require('fs');

test('run inspect()', function (t) {
t.plan(1);
return plugin.inspect(
__dirname + '/../fixtures/testproj/',
'build.sbt')
.then(function (result) {
t.equal(result.package
.dependencies['com.example:hello_2.12']
.dependencies['axis:axis']
.dependencies['axis:axis-jaxrpc']
.dependencies['org.apache.axis:axis-jaxrpc'].version,
'1.4',
'correct version found');
});
});

0 comments on commit 838302d

Please sign in to comment.