Skip to content

Commit 1962ed8

Browse files
authored
Merge pull request #88 from electricimp/develop
Version 3.2.0 Release
2 parents d390dbe + 0ef3307 commit 1962ed8

15 files changed

+1002
-173
lines changed

Diff for: README.md

+77-22
Large diffs are not rendered by default.

Diff for: package-lock.json

+141-141
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "Builder",
3-
"version": "3.0.0",
3+
"version": "3.2.0",
44
"description": "Builder Language Implementation",
55
"main": "src/index.js",
66
"bin": {
@@ -9,6 +9,7 @@
99
"scripts": {
1010
"test": "jasmine",
1111
"test:bitbucket-server": "node ./spec/BitbucketServerExecutor.js",
12+
"test:azure-repos": "node ./spec/AzureReposExecutor.js",
1213
"build": "src/cli.js input"
1314
},
1415
"repository": {

Diff for: spec/AzureRepos/AzureReposReader.spec.js

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
// MIT License
2+
//
3+
// Copyright 2020 Electric Imp
4+
//
5+
// SPDX-License-Identifier: MIT
6+
//
7+
// Permission is hereby granted, free of charge, to any person obtaining a copy
8+
// of this software and associated documentation files (the "Software"), to deal
9+
// in the Software without restriction, including without limitation the rights
10+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
// copies of the Software, and to permit persons to whom the Software is
12+
// furnished to do so, subject to the following conditions:
13+
//
14+
// The above copyright notice and this permission notice shall be
15+
// included in all copies or substantial portions of the Software.
16+
//
17+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18+
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19+
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO
20+
// EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES
21+
// OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
22+
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23+
// OTHER DEALINGS IN THE SOFTWARE.
24+
25+
'use strict';
26+
27+
const fs = require('fs');
28+
const Log = require('log');
29+
const eol = require('eol');
30+
const AzureReposReader = require('../../src/Readers/AzureReposReader');
31+
32+
describe('AzureReposReader', () => {
33+
let reader;
34+
35+
beforeEach(function() {
36+
if (!process.env.SPEC_AZURE_REPOS_REPO_PATH) {
37+
fail('Some of the required environment variables are not set');
38+
return;
39+
}
40+
41+
reader = new AzureReposReader();
42+
43+
// @see https://www.npmjs.com/package/log#log-levels
44+
reader.logger = new Log(process.env.SPEC_LOGLEVEL || 'error');
45+
reader.username = process.env.SPEC_AZURE_REPOS_USERNAME;
46+
reader.token = process.env.SPEC_AZURE_REPOS_TOKEN;
47+
});
48+
49+
it('should read sample#1 from Azure Repos', () => {
50+
let remote;
51+
const local = eol.lf(fs.readFileSync(__dirname + '/../fixtures/sample-1/input.nut', 'utf-8'));
52+
53+
remote = reader.read(`git-azure-repos:${process.env.SPEC_AZURE_REPOS_REPO_PATH}/spec/fixtures/sample-1/input.nut`);
54+
expect(remote).toEqual(local);
55+
56+
remote = reader.read(`git-azure-repos:${process.env.SPEC_AZURE_REPOS_REPO_PATH}/spec/fixtures/sample-1/input.nut@master`);
57+
expect(remote).toEqual(local);
58+
59+
remote = reader.read(`git-azure-repos:${process.env.SPEC_AZURE_REPOS_REPO_PATH}/./spec/../spec/fixtures/sample-1/input.nut`);
60+
expect(remote).toEqual(local);
61+
62+
remote = reader.read(`git-azure-repos:${process.env.SPEC_AZURE_REPOS_REPO_PATH}/./spec/../spec/fixtures/sample-1/input.nut@master`);
63+
expect(remote).toEqual(local);
64+
});
65+
});

Diff for: spec/AzureRepos/branches-tags-commits.spec.js

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
// MIT License
2+
//
3+
// Copyright 2020 Electric Imp
4+
//
5+
// SPDX-License-Identifier: MIT
6+
//
7+
// Permission is hereby granted, free of charge, to any person obtaining a copy
8+
// of this software and associated documentation files (the "Software"), to deal
9+
// in the Software without restriction, including without limitation the rights
10+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
// copies of the Software, and to permit persons to whom the Software is
12+
// furnished to do so, subject to the following conditions:
13+
//
14+
// The above copyright notice and this permission notice shall be
15+
// included in all copies or substantial portions of the Software.
16+
//
17+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18+
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19+
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO
20+
// EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES
21+
// OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
22+
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23+
// OTHER DEALINGS IN THE SOFTWARE.
24+
25+
'use strict';
26+
27+
const fs = require('fs');
28+
const Log = require('log');
29+
const eol = require('eol');
30+
const AzureReposReader = require('../../src/Readers/AzureReposReader');
31+
32+
describe('AzureReposReader', () => {
33+
let reader;
34+
35+
beforeEach(function() {
36+
if (!process.env.SPEC_AZURE_REPOS_REPO_PATH) {
37+
fail('Some of the required environment variables are not set');
38+
return;
39+
}
40+
41+
reader = new AzureReposReader();
42+
43+
// @see https://www.npmjs.com/package/log#log-levels
44+
reader.logger = new Log(process.env.SPEC_LOGLEVEL || 'error');
45+
reader.username = process.env.SPEC_AZURE_REPOS_USERNAME;
46+
reader.token = process.env.SPEC_AZURE_REPOS_TOKEN;
47+
});
48+
49+
it('should read sample#1 from Azure Repos with refs', () => {
50+
let remote;
51+
const local = eol.lf(fs.readFileSync(__dirname + '/../fixtures/sample-1/input.nut', 'utf-8'));
52+
53+
remote = reader.read(`git-azure-repos:${process.env.SPEC_AZURE_REPOS_REPO_PATH}/spec/fixtures/sample-1/input.nut@master`);
54+
expect(remote).toEqual(local);
55+
56+
remote = reader.read(`git-azure-repos:${process.env.SPEC_AZURE_REPOS_REPO_PATH}/spec/fixtures/sample-1/input.nut@v0.1.0`);
57+
expect(remote).toEqual(local);
58+
59+
remote = reader.read(`git-azure-repos:${process.env.SPEC_AZURE_REPOS_REPO_PATH}/spec/fixtures/sample-1/input.nut@d390dbe849da349e29db850779173887c5e9babd`);
60+
expect(remote).toEqual(local);
61+
});
62+
});

Diff for: spec/AzureRepos/cache.spec.js

+101
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
// MIT License
2+
//
3+
// Copyright 2020 Electric Imp
4+
//
5+
// SPDX-License-Identifier: MIT
6+
//
7+
// Permission is hereby granted, free of charge, to any person obtaining a copy
8+
// of this software and associated documentation files (the "Software"), to deal
9+
// in the Software without restriction, including without limitation the rights
10+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
// copies of the Software, and to permit persons to whom the Software is
12+
// furnished to do so, subject to the following conditions:
13+
//
14+
// The above copyright notice and this permission notice shall be
15+
// included in all copies or substantial portions of the Software.
16+
//
17+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18+
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19+
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO
20+
// EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES
21+
// OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
22+
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23+
// OTHER DEALINGS IN THE SOFTWARE.
24+
25+
'use strict';
26+
27+
require('jasmine-expect');
28+
29+
const fs = require('fs');
30+
const Log = require('log');
31+
const Builder = require('../../src/');
32+
33+
describe('FileCache', () => {
34+
let machine;
35+
36+
beforeEach(() => {
37+
if (!process.env.SPEC_AZURE_REPOS_REPO_PATH) {
38+
fail('Some of the required environment variables are not set');
39+
return;
40+
}
41+
42+
const builder = new Builder();
43+
builder.logger = new Log(process.env.SPEC_LOGLEVEL || 'error');
44+
builder.machine.readers.azureRepos.username = process.env.SPEC_AZURE_REPOS_USERNAME;
45+
builder.machine.readers.azureRepos.token = process.env.SPEC_AZURE_REPOS_TOKEN;
46+
machine = builder.machine;
47+
48+
machine.fileCache.cacheDir = './test-cache';
49+
});
50+
51+
afterEach(() => {
52+
if (!machine) {
53+
return;
54+
}
55+
56+
if (fs.existsSync(machine.fileCache.cacheDir)) {
57+
machine.clearCache();
58+
}
59+
});
60+
61+
it('should not read cached files when cache option is off', () => {
62+
let link = `git-azure-repos:${process.env.SPEC_AZURE_REPOS_REPO_PATH}/spec/fixtures/sample-11/LineBrakeSample.nut`;
63+
machine.useCache = false;
64+
machine.fileCache._cacheFile(link, 'cached');
65+
expect(machine.execute(`@include '${link}'`)).not.toEqual('cached');
66+
});
67+
68+
it('should cache files in machine', () => {
69+
let link = `git-azure-repos:${process.env.SPEC_AZURE_REPOS_REPO_PATH}/spec/fixtures/sample-11/LineBrakeSample.nut`;
70+
machine.useCache = true;
71+
machine.execute(`@include '${link}'`);
72+
expect(machine.fileCache._findFile(link)).toBeTruthy();
73+
});
74+
75+
it('should exclude remote files from cache', () => {
76+
machine.useCache = true;
77+
let linkName = `git-azure-repos:${process.env.SPEC_AZURE_REPOS_REPO_PATH}/spec/fixtures/sample-11/LineBrakeSample.nut`;
78+
expect(machine.fileCache._findFile(linkName)).toEqual(false);
79+
machine.excludeList = __dirname + '/../fixtures/config/exclude-all.exclude';
80+
machine.execute(`@include '${linkName}'`);
81+
expect(machine.fileCache._findFile(linkName)).toEqual(false);
82+
});
83+
84+
it('should generate unique paths for different Azure Repos links', () => {
85+
const linksSet = new Set();
86+
const links = ['git-azure-repos:a/b/c.js',
87+
'git-azure-repos:b/a/c.js',
88+
'git-azure-repos:a/b/c.js@a',
89+
'git-azure-repos:a/b/c.j@s',
90+
'git-azure-repos:a/b/a-b-c.js',
91+
'git-azure-repos:a/b-c_js/c.js',
92+
'git-azure-repos:a/b/c_js.js',
93+
'git-azure-repos:a/b/c/js'
94+
];
95+
links.forEach(link => {
96+
const path = machine.fileCache._getCachedPath(link);
97+
expect(linksSet.has(path)).toEqual(false);
98+
linksSet.add(path);
99+
});
100+
});
101+
});

Diff for: spec/AzureRepos/dependencies.spec.js

+88
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
// MIT License
2+
//
3+
// Copyright 2020 Electric Imp
4+
//
5+
// SPDX-License-Identifier: MIT
6+
//
7+
// Permission is hereby granted, free of charge, to any person obtaining a copy
8+
// of this software and associated documentation files (the "Software"), to deal
9+
// in the Software without restriction, including without limitation the rights
10+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
// copies of the Software, and to permit persons to whom the Software is
12+
// furnished to do so, subject to the following conditions:
13+
//
14+
// The above copyright notice and this permission notice shall be
15+
// included in all copies or substantial portions of the Software.
16+
//
17+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18+
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19+
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO
20+
// EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES
21+
// OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
22+
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23+
// OTHER DEALINGS IN THE SOFTWARE.
24+
25+
'use strict';
26+
27+
require('jasmine-expect');
28+
29+
const fs = require('fs');
30+
const path = require('path');
31+
const eol = require('eol');
32+
const Log = require('log');
33+
const Builder = require('../../src/');
34+
35+
const dependenciesFile = path.join(process.cwd(), 'save_dependencies.json');
36+
37+
describe('Machine', () => {
38+
let machine;
39+
40+
beforeEach(function () {
41+
if (!process.env.SPEC_AZURE_REPOS_REPO_PATH) {
42+
fail('Some of the required environment variables are not set');
43+
return;
44+
}
45+
46+
const builder = new Builder();
47+
builder.logger = new Log(process.env.SPEC_LOGLEVEL || 'error');
48+
builder.machine.readers.azureRepos.username = process.env.SPEC_AZURE_REPOS_USERNAME;
49+
builder.machine.readers.azureRepos.token = process.env.SPEC_AZURE_REPOS_TOKEN;
50+
machine = builder.machine;
51+
});
52+
53+
it('Create and read dependencies JSON file', () => {
54+
const rev1CommitID = "618bb5ecb831762ed085486f39496502f7b22700";
55+
const rev1Content = "// included file a\n// included file b\n\n\n // should be included\n\n // l2 else\n\n\n // should be included\n";
56+
const rev0CommitID = "e2a5b434b34b5737b2ff52f51a92c5bbcc9f83bf";
57+
const rev0Content = "// included file a\n // included file b\n\n\n // should be included\n\n // l2 else\n\n\n // should be included\n";
58+
const url = `git-azure-repos:${process.env.SPEC_AZURE_REPOS_REPO_PATH}/spec/fixtures/sample-1/input.nut.out@v2.2.2`;
59+
60+
// ensure that test dependencies JSON file does not exist
61+
if (fs.existsSync(dependenciesFile)) {
62+
fs.unlinkSync(dependenciesFile);
63+
}
64+
65+
machine.dependenciesSaveFile = dependenciesFile;
66+
expect(eol.lf(machine.execute(`@include "${url}"`))).toBe(rev1Content);
67+
68+
// check dependencies JSON file content
69+
const rev1Map = new Map(JSON.parse(fs.readFileSync(dependenciesFile)));
70+
expect(rev1Map.size).toEqual(1);
71+
expect(rev1Map.get(url)).toEqual(rev1CommitID);
72+
73+
// replace the actual (rev1) commit ID to rev0 commit ID
74+
rev1Map.set(url, rev0CommitID);
75+
fs.writeFileSync(dependenciesFile, JSON.stringify([...rev1Map], null, 2), 'utf-8');
76+
77+
machine.dependenciesUseFile = dependenciesFile;
78+
expect(eol.lf(machine.execute(`@include "${url}"`))).toBe(rev0Content);
79+
80+
// check dependencies JSON file content again
81+
const rev0Map = new Map(JSON.parse(fs.readFileSync(dependenciesFile)));
82+
expect(rev0Map.size).toEqual(1);
83+
expect(rev0Map.get(url)).toEqual(rev0CommitID);
84+
85+
// unlink dependencies file to avoid conflicts with unit-tests below
86+
fs.unlinkSync(dependenciesFile);
87+
});
88+
});

0 commit comments

Comments
 (0)