Skip to content

Commit

Permalink
Merge pull request #44 from snyk/feat/windows-system-tests
Browse files Browse the repository at this point in the history
fix: enable system tests on windows
  • Loading branch information
lili2311 committed Jul 1, 2019
2 parents 92c5fa1 + 4dae3d7 commit e247217
Show file tree
Hide file tree
Showing 7 changed files with 163 additions and 30 deletions.
30 changes: 12 additions & 18 deletions appveyor.yml
@@ -1,33 +1,28 @@
build: off
os: Windows Server 2012

init:
- git config --global core.autocrlf input

install:
- java -version
- SET JAVA_HOME=C:\jdk8
- SET PATH=C:\jdk8\bin;%PATH%

- ps: |
Add-Type -AssemblyName System.IO.Compression.FileSystem
if (!(Test-Path -Path "C:\sbt" )) {
(new-object System.Net.WebClient).DownloadFile(
'https://piccolo.link/sbt-0.13.18.zip',
'C:\sbt-bin.zip'
)
[System.IO.Compression.ZipFile]::ExtractToDirectory("C:\sbt-bin.zip", "C:\sbt")
}
- SET PATH=C:\sbt\sbt\bin;%PATH%
- SET SBT_OPTS=-Xmx4g -Dfile.encoding=UTF8
- cmd: choco install zulu8 -ia "INSTALLDIR=""C:\zulu"""
- cmd: SET JAVA_HOME="C:\zulu"
- cmd: choco install sbt -ia "INSTALLDIR=""C:\sbt"""
- cmd: SET PATH=C:\sbt\bin;%JAVA_HOME%\bin;%PATH%
- cmd: SET SBT_OPTS=-Xms4g -Xmx4g
- cmd: SET COURSIER_VERBOSITY=-1
- cmd: SET JAVA_OPTS=-Xms4g -Xmx4g
- ps: Install-Product node $env:nodejs_version
- java -version
- node --version
- npm --version
- npm install

cache:
- '%USERPROFILE%\.ivy2\cache'
- '%USERPROFILE%\.ivy2'
- '%USERPROFILE%\.sbt'
- node_modules -> package.json
- C:\Users\appveyor\.m2


branches:
Expand All @@ -44,5 +39,4 @@ environment:

test_script:
- npm test
# TODO: fix setu and re-enable
# - npm run test-system
- npm run test-system-windows
2 changes: 1 addition & 1 deletion lib/index.ts
Expand Up @@ -185,7 +185,7 @@ function searchWithFs( filename ) {

export function buildArgs(sbtArgs, isCoursierProject?: boolean) {
// force plain output so we don't have to parse colour codes
let args = ['-Dsbt.log.noformat=true'];
let args = ['\"-Dsbt.log.noformat=true\"'];
if (sbtArgs) {
args = args.concat(sbtArgs);
}
Expand Down
3 changes: 2 additions & 1 deletion package.json
Expand Up @@ -19,7 +19,8 @@
"prepare": "npm run build",
"test": "npm run lint && npm run build && npm run test-functional",
"test-functional": "tap -Rspec ./test/functional/*.test.[tj]s",
"test-system": "tap -Rspec --timeout=600 ./test/system/*.test.[tj]s"
"test-system": "tap -Rspec --timeout=600 ./test/system/*.test.[tj]s",
"test-system-windows": "tap -Rspec --timeout=600 ./test/system-windows/*.test.[tj]s"
},
"author": "snyk.io",
"license": "Apache-2.0",
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/testproj-1.2.8/project/site.sbt
@@ -1 +1,2 @@
addSbtPlugin("net.virtual-void" % "sbt-dependency-graph" % "0.9.2")
ThisBuild / scalaVersion := "2.12.8"
8 changes: 4 additions & 4 deletions test/functional/sbt-plugin.test.ts
Expand Up @@ -7,7 +7,7 @@ test('check build args with array not coursier', (t) => {
'-Pjaxen',
], false);
t.deepEqual(result, [
'-Dsbt.log.noformat=true',
'"-Dsbt.log.noformat=true\"',
'-Paxis',
'-Pjaxen',
'dependencyTree',
Expand All @@ -18,7 +18,7 @@ test('check build args with array not coursier', (t) => {
test('check build args with string not coursie', (t) => {
const result = plugin.buildArgs('-Paxis -Pjaxen', false);
t.deepEqual(result, [
'-Dsbt.log.noformat=true',
'"-Dsbt.log.noformat=true\"',
'-Paxis -Pjaxen',
'dependencyTree',
]);
Expand All @@ -31,7 +31,7 @@ test('check build args with array for coursier', (t) => {
'-Pjaxen',
], true);
t.deepEqual(result, [
'-Dsbt.log.noformat=true',
'"-Dsbt.log.noformat=true\"',
'-Paxis',
'-Pjaxen',
'coursierDependencyTree',
Expand All @@ -42,7 +42,7 @@ test('check build args with array for coursier', (t) => {
test('check build args with string for coursier', (t) => {
const result = plugin.buildArgs('-Paxis -Pjaxen', true);
t.deepEqual(result, [
'-Dsbt.log.noformat=true',
'"-Dsbt.log.noformat=true\"',
'-Paxis -Pjaxen',
'coursierDependencyTree',
]);
Expand Down
118 changes: 118 additions & 0 deletions test/system-windows/plugin.test.ts
@@ -0,0 +1,118 @@
import * as path from 'path';
import * as test from 'tap-only';
// import * as sinon from 'sinon';
import * as plugin from '../../lib';
// import * as subProcess from '../../lib/sub-process';

test('run inspect() 0.13', async (t) => {
const result: any = await plugin.inspect(path.join(__dirname, '..', 'fixtures'),
'testproj-0.13/build.sbt', { debug: true});
// top level package is not added as a dep on windows
t.equal(result.package.version, '1.4');
t.match(result.package.name, 'axis:axis');
t.deepEqual(result.package
.dependencies['axis:axis-jaxrpc']
.dependencies['org.apache.axis:axis-jaxrpc'].version,
'1.4',
'correct version found');
});

test('run inspect() on 1.2.8', async (t) => {
const result: any = await plugin.inspect(path.join(__dirname, '..', 'fixtures'),
'testproj-1.2.8/build.sbt', {});
// top level package is not added as a dep on windows
t.equal(result.package.version, '1.4');
t.match(result.package.name, 'axis:axis');
t.deepEqual(result.package
.dependencies['axis:axis-jaxrpc']
.dependencies['org.apache.axis:axis-jaxrpc'].version,
'1.4',
'correct version found');
});

// TODO: fix coursier on windows
// test('run inspect() with coursier on 0.17', async (t) => {
// const result: any = await plugin.inspect(path.join(__dirname, '..', 'fixtures'),
// 'testproj-coursier-0.13/build.sbt', {});
// // top level package is not added as a dep on windows
// t.equal(result.package.version, '1.4');
// t.match(result.package.name, 'axis:axis');
// t.deepEqual(result.package
// .dependencies['axis:axis-jaxrpc']
// .dependencies['org.apache.axis:axis-jaxrpc'].version,
// '1.4',
// 'correct version found');
// });

// test('run inspect() with coursier on 1.2.8', async (t) => {
// const result: any = await plugin.inspect(path.join(__dirname, '..', 'fixtures'),
// 'testproj-coursier-1.2.8/build.sbt', {});
// // top level package is not added as a dep on windows
// t.equal(result.package.version, '1.4');
// t.match(result.package.name, 'axis:axis');
// t.deepEqual(result.package
// .dependencies['axis:axis-jaxrpc']
// .dependencies['org.apache.axis:axis-jaxrpc'].version,
// '1.4',
// 'correct version found');
// });

test('run inspect() with no sbt plugin on 0.13', async (t) => {
try {
await plugin.inspect(path.join(
__dirname, '..', 'fixtures', 'testproj-noplugin-0.13'),
'build.sbt', {});
t.fail('should not be reached');
} catch (error) {
t.match(error.message, 'the `sbt-dependency-graph` plugin');
t.pass('Error thrown correctly');
}
});

test('run inspect() with commented out coursier on 0.13', async (t) => {
const result: any = await plugin.inspect(path.join(
__dirname, '..', 'fixtures', 'testproj-faux-coursier-0.13'),
'build.sbt', {});
// top level package is not added as a dep on windows
t.equal(result.package.version, '1.4');
t.match(result.package.name, 'axis:axis');
t.deepEqual(result.package
.dependencies['axis:axis-jaxrpc']
.dependencies['org.apache.axis:axis-jaxrpc'].version,
'1.4',
'correct version found');
});

// TODO: fix, seems to timeout?
// test('run inspect() on bad project requiring user input', async (t) => {
// try {
// await plugin.inspect(path.join(__dirname, '..', 'fixtures',
// 'bad-project'), 'build.sbt', {});
// t.fail('Expected to fail');
// } catch (error) {
// t.match(error.message, 'code: 1');
// t.match(error.message, '(q)uit');
// t.pass('Error thrown correctly');
// }
// });

// TODO: fix, seems to timeout?
// test('run inspect() with failing `sbt` execution', async (t) => {
// stubSubProcessExec(t);
// try {
// await plugin.inspect(path.join(__dirname, '..', 'fixtures'),
// 'testproj-0.13/build.sbt', {});
// t.fail('should not be reached');
// } catch (error) {
// t.match(error.message, 'abort');
// t.pass('Error thrown correctly');
// }
// });

// function stubSubProcessExec(t) {
// const executeStub = sinon.stub(subProcess, 'execute')
// .callsFake(() => {
// return Promise.reject(new Error('abort'));
// });
// t.teardown(executeStub.restore);
// }
31 changes: 25 additions & 6 deletions test/system/plugin.test.ts
Expand Up @@ -4,10 +4,13 @@ import * as sinon from 'sinon';
import * as plugin from '../../lib';
import * as subProcess from '../../lib/sub-process';

test('run inspect()', async (t) => {
test('run inspect() 0.13', async (t) => {
const result: any = await plugin.inspect(path.join(__dirname, '..', 'fixtures'),
'testproj-0.13/build.sbt', { debug: true});
t.equal(result.package
t.equal(result.package.version, '0.1.0-SNAPSHOT');
t.match(result.package.name, 'hello');

t.deepEqual(result.package
.dependencies['axis:axis']
.dependencies['axis:axis-jaxrpc']
.dependencies['org.apache.axis:axis-jaxrpc'].version,
Expand All @@ -18,7 +21,9 @@ test('run inspect()', async (t) => {
test('run inspect() on 1.2.8', async (t) => {
const result: any = await plugin.inspect(path.join(__dirname, '..', 'fixtures'),
'testproj-1.2.8/build.sbt', {});
t.equal(result.package
t.equal(result.package.version, '0.1.0-SNAPSHOT');
t.match(result.package.name, 'hello');
t.deepEqual(result.package
.dependencies['axis:axis']
.dependencies['axis:axis-jaxrpc']
.dependencies['org.apache.axis:axis-jaxrpc'].version,
Expand All @@ -29,7 +34,12 @@ test('run inspect() on 1.2.8', async (t) => {
test('run inspect() with coursier on 0.17', async (t) => {
const result: any = await plugin.inspect(path.join(__dirname, '..', 'fixtures'),
'testproj-coursier-0.13/build.sbt', {});
t.equal(result.package
// TODO: fix to get the project name from build.sbt
// for coursier project
// t.equal(result.package.version, '0.1.0-SNAPSHOT')
// t.match(result.package.name, 'hello');
t.ok(result.package.dependencies['axis:axis']);
t.deepEqual(result.package
.dependencies['axis:axis']
.dependencies['axis:axis-jaxrpc']
.dependencies['org.apache.axis:axis-jaxrpc'].version,
Expand All @@ -40,7 +50,12 @@ test('run inspect() with coursier on 0.17', async (t) => {
test('run inspect() with coursier on 1.2.8', async (t) => {
const result: any = await plugin.inspect(path.join(__dirname, '..', 'fixtures'),
'testproj-coursier-1.2.8/build.sbt', {});
t.equal(result.package
// TODO: fix to get the project name from build.sbt
// for coursier project
// t.equal(result.package.version, '0.1.0-SNAPSHOT');
// t.match(result.package.name, 'hello');
t.ok(result.package.dependencies['axis:axis']);
t.deepEqual(result.package
.dependencies['axis:axis']
.dependencies['axis:axis-jaxrpc']
.dependencies['org.apache.axis:axis-jaxrpc'].version,
Expand All @@ -64,7 +79,11 @@ test('run inspect() with commented out coursier on 0.13', async (t) => {
const result: any = await plugin.inspect(path.join(
__dirname, '..', 'fixtures', 'testproj-faux-coursier-0.13'),
'build.sbt', {});
t.equal(result.package
// TODO: fix to get the project name from build.sbt
// t.equal(result.package.version, '0.1.0-SNAPSHOT');
t.match(result.package.name, 'hello');
t.ok(result.package.dependencies['axis:axis']);
t.deepEqual(result.package
.dependencies['axis:axis']
.dependencies['axis:axis-jaxrpc']
.dependencies['org.apache.axis:axis-jaxrpc'].version,
Expand Down

0 comments on commit e247217

Please sign in to comment.