Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Continuous Integration on Windows #1103

Merged
merged 17 commits into from
Aug 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
45 changes: 30 additions & 15 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,37 @@ commands:

orbs:
helix-smoke-tests: adobe/helix-smoke-tests@0.0.7
win: circleci/windows-tools@0.0.4

jobs:
snyk:
executor: node8
working_directory: ~/repo

build_win:
parallelism: 1
executor: win/preview-default
steps:
- setup

- run:
name: prepare test git user
command: git config --global user.email "you@example.com" && git config --global user.name "Your Name"

# test & get code coverage
- run:
name: Running Tests with Snyk Agent
command: node snykmocha.js
- run: git config --global core.autocrlf false
- run:
name: prepare test git user
command: git config --global user.email "circleci@project-helix.io"
- run:
name: prepare test git user
command: git config --global user.name "CircleCi Build"
- checkout
- run: choco install nodejs --version 10.16.0
- run: npm install
- run: mkdir junit

# test & get code coverage
- run:
name: Test and Code Coverage
command: npm run test-ci-win
environment:
MOCHA_FILE: junit/test-results.xml

- store_test_results:
path: junit

- store_artifacts:
path: junit

build:
parallelism: 4
Expand Down Expand Up @@ -104,11 +118,12 @@ workflows:
- publish-pre-release:
requires:
- build
- build_win
filters:
branches:
only: master
- build
- snyk
- build_win

smoke:
jobs:
Expand Down
20 changes: 10 additions & 10 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"check": "npm run lint && npm run test",
"test": "nyc --lines 90 --reporter=text --reporter=lcov mocha -t 5000",
"test-ci": "circleci tests glob 'test/test*.js' | circleci tests split --split-by=timings | xargs nyc --reporter=text --reporter=lcov mocha -R mocha-junit-reporter -t 5000 && codecov",
"test-ci-win": "./node_modules/.bin/mocha --reporter xunit test --reporter-options output=junit/test.xml -t 5000",
"lint": "./node_modules/.bin/eslint .",
"lint-ci": "circleci tests glob 'src/**/*.js' 'test/**/*.js' | circleci tests split | xargs eslint",
"semantic-release": "semantic-release",
Expand Down Expand Up @@ -37,7 +38,7 @@
"@adobe/fastly-native-promises": "^1.10.0",
"@adobe/helix-pipeline": "4.0.5",
"@adobe/helix-shared": "2.1.1",
"@adobe/helix-simulator": "2.12.18",
"@adobe/helix-simulator": "2.12.19",
"@adobe/htlengine": "3.2.1",
"@babel/core": "^7.5.5",
"@parcel/logger": "^1.11.0",
Expand Down
4 changes: 4 additions & 0 deletions test/testBuildCmd.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ describe('Integration test for build', function suite() {
return true;
});

afterEach(async () => {
await fs.remove(testRoot);
});

it('build command succeeds and produces files', async () => {
await new BuildCommand()
.withFiles(['test/integration/src/**/*.htl', 'test/integration/src/**/*.js'])
Expand Down
17 changes: 9 additions & 8 deletions test/testCleanCmd.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

const path = require('path');
const fs = require('fs-extra');
const assert = require('assert');
const sinon = require('sinon');

const {
Expand All @@ -40,6 +39,10 @@ describe('Integration test for clean', () => {
return true;
});

afterEach(async () => {
await fs.remove(testRoot);
});

it('clean command succeeds and removes files', async () => {
// add some files to the directories
const testFile1 = path.resolve(buildDir, 'html.htl');
Expand Down Expand Up @@ -86,12 +89,10 @@ describe('Integration test for clean', () => {
await fs.copy(path.resolve(testRoot, 'src', 'html.htl'), testFile1);
const stub = sinon.stub(fs, 'remove')
.throws(new Error('oops'));
assert.doesNotThrow(async () => {
await new CleanCommand()
.withDirectory(testRoot)
.withTargetDir(buildDir)
.run();
stub.restore();
});
await new CleanCommand()
.withDirectory(testRoot)
.withTargetDir(buildDir)
.run();
stub.restore();
});
});
2 changes: 2 additions & 0 deletions test/testCli.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ describe('hlx command line', () => {
const cmd = runCLI('--version');
assert.equal(cmd.code, 0);
assert.ok(cmd.stdout.trim().indexOf('This is typically not good because it might contain secrets') >= 0);
shell.cd(cwd);
await fse.remove(testRoot);
});

it('un-supported node version should give warning', async () => {
Expand Down
3 changes: 2 additions & 1 deletion test/testDemoCmd.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ describe('Integration test for demo command', function suite() {
testDir = await createTestRoot();
});

afterEach('Change back to original working dir', () => {
afterEach('Change back to original working dir', async () => {
process.chdir(pwd);
await fs.remove(testDir);
});

it('demo type simple creates all files', async () => {
Expand Down
3 changes: 2 additions & 1 deletion test/testDeployCmd.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,9 @@ describe('hlx deploy (Integration)', () => {
});
});

afterEach(() => {
afterEach(async () => {
$.cd(cwd);
await fs.remove(testRoot);
});

it('deploy fails if no helix-config is present.', async () => {
Expand Down
23 changes: 12 additions & 11 deletions test/testGitUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ git.plugins.set('fs', require('fs'));

const GitUtils = require('../src/git-utils');

const GIT_USER_HOME = path.resolve(__dirname, 'fixtures/gitutils');
const GIT_USER_HOME = path.resolve(__dirname, 'fixtures', 'gitutils');

const isNotWindows = () => (process.platform !== 'win32');

if (!shell.which('git')) {
shell.echo('Sorry, this tests requires git');
Expand Down Expand Up @@ -82,7 +84,8 @@ describe('Testing GitUtils', () => {
assert.equal(await GitUtils.isDirty(testRoot, GIT_USER_HOME), true);
});

it('isDirty #unit with submodules', async () => {
// windows has somehow problems wit adding file:// submodules. so we skip for now.
condit('isDirty #unit with submodules', isNotWindows, async () => {
// https://github.com/adobe/helix-cli/issues/614
const moduleRoot = await createTestRoot();

Expand Down Expand Up @@ -129,11 +132,7 @@ describe('Testing GitUtils', () => {
assert.equal(await GitUtils.isDirty(testRoot, GIT_USER_HOME), false);
});

it('isDirty #unit with unix socket', async function socketTest() {
if (process.platform === 'win32') {
this.skip();
return;
}
condit('isDirty #unit with unix socket', isNotWindows, async () => {
assert.equal(await GitUtils.isDirty(testRoot, GIT_USER_HOME), false);

await new Promise((resolve) => {
Expand Down Expand Up @@ -181,6 +180,8 @@ describe('Testing GitUtils', () => {
});

describe('Tests against the helix-cli repo', () => {
const repoDir = path.resolve(__dirname, '..');

function ishelix() {
if (process.env.CIRCLE_REPOSITORY_URL) {
return !!process.env.CIRCLE_REPOSITORY_URL.match('helix-cli');
Expand All @@ -189,25 +190,25 @@ describe('Tests against the helix-cli repo', () => {
}

condit('resolveCommit resolves the correct commit for tags', ishelix, async () => {
const commit = await GitUtils.resolveCommit('.', 'v1.0.0');
const commit = await GitUtils.resolveCommit(repoDir, 'v1.0.0');
assert.equal(commit, 'f9ab59cd2baa2860289d826e270938f2eedb3e59');
});

condit('resolveCommit resolves the correct commit for shortened OID', ishelix, async () => {
const commit = await GitUtils.resolveCommit('.', 'f9ab59c');
const commit = await GitUtils.resolveCommit(repoDir, 'f9ab59c');
assert.equal(commit, 'f9ab59cd2baa2860289d826e270938f2eedb3e59');
});

condit('resolveCommit throws for unknown ref', ishelix, async () => {
await assert.rejects(async () => GitUtils.resolveCommit('.', 'v99.unicorn.foobar'), { code: 'ResolveRefError' });
await assert.rejects(async () => GitUtils.resolveCommit(repoDir, 'v99.unicorn.foobar'), { code: 'ResolveRefError' });
});

it('resolveCommit throws for invalid argument type', async () => {
await assert.rejects(async () => GitUtils.resolveCommit(1.0, true), { name: 'TypeError' });
});

condit('getRawContent gets the correct version', ishelix, async () => {
const content = await GitUtils.getRawContent('.', 'v1.0.0', 'package.json');
const content = await GitUtils.getRawContent(repoDir, 'v1.0.0', 'package.json');
assert.equal(JSON.parse(content.toString()).version, '1.0.0');
});
});
4 changes: 2 additions & 2 deletions test/testJUnitUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ describe('Test Junit Report Builder', () => {
root = await createTestRoot();
});

afterEach(() => {
// fs.removeSync(root);
afterEach(async () => {
await fs.remove(root);
});

it('Responses can be appended', () => {
Expand Down
4 changes: 2 additions & 2 deletions test/testPackageCmd.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ describe('hlx package (Integration)', () => {
buildDir = path.resolve(hlxDir, 'build');
});

afterEach(() => {
fs.remove(testRoot);
afterEach(async () => {
await fs.remove(testRoot);
});

it('package creates correct package', async () => {
Expand Down