Skip to content

Commit

Permalink
Add prettier and format code (#28)
Browse files Browse the repository at this point in the history
* add prettier as depedency

* add prettier configuration files

* run prettier
  • Loading branch information
dbanck authored Mar 15, 2022
1 parent c010f3f commit 6a48ccf
Show file tree
Hide file tree
Showing 9 changed files with 219 additions and 203 deletions.
8 changes: 4 additions & 4 deletions .mocharc.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"extension": ["ts"],
"spec": "src/**/*.test.ts",
"require": "ts-node/register"
}
"extension": ["ts"],
"spec": "src/**/*.test.ts",
"require": "ts-node/register"
}
3 changes: 3 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
out/
package-lock.json
node_modules/
9 changes: 9 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"endOfLine": "lf",
"printWidth": 120,
"semi": true,
"singleQuote": true,
"tabWidth": 2,
"trailingComma": "all",
"useTabs": false
}
6 changes: 6 additions & 0 deletions package-lock.json

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

6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
"compile": "tsc -b",
"watch": "tsc -b -w",
"test": "mocha",
"prepare": "npm run-script test && npm run-script compile"
"prepare": "npm run-script test && npm run-script compile",
"prettier": "prettier \"**/*.+(js|json|ts)\"",
"format": "npm run prettier -- --write",
"check-format": "npm run prettier -- --check"
},
"repository": {
"type": "git",
Expand All @@ -33,6 +36,7 @@
"@types/node": "^14.18.10",
"@types/yauzl": "^2.9.2",
"mocha": "^9.2.0",
"prettier": "^2.5.1",
"tempy": "^1.0.1",
"ts-node": "^9.1.1",
"typescript": "^4.2.4"
Expand Down
104 changes: 49 additions & 55 deletions src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,62 +3,56 @@ import * as path from 'path';
import * as fs from 'fs';
import * as tempy from 'tempy';


import { Release } from './index';

describe('LS installer', () => {
let release: Release;

before(() => {
release = new Release({
name: 'terraform-ls',
version: '0.25.2',
shasums: 'terraform-ls_0.25.2_SHA256SUMS',
shasums_signature: 'terraform-ls_0.25.2_SHA256SUMS.sig',
shasums_signatures: [
'terraform-ls_0.25.2_SHA256SUMS.72D7468F.sig',
'terraform-ls_0.25.2_SHA256SUMS.sig',
],
builds: [
{
name: 'terraform-ls',
version: '0.25.2',
os: 'darwin',
arch: 'amd64',
filename: 'terraform-ls_0.25.2_darwin_amd64.zip',
url: 'https://releases.hashicorp.com/terraform-ls/0.25.2/terraform-ls_0.25.2_darwin_amd64.zip',
},
],
});
});

it('should calculate correct file sha256 sum', async () => {
const expectedSum = "0314c6a66b059bde92c5ed0f11601c144cbd916eff6d1241b5b44e076e5888dc";
const testPath = path.resolve(__dirname, "..", "testFixture", "shasumtest.txt");

const sum = await release.calculateFileSha256Sum(testPath);
assert.strictEqual(sum, expectedSum);
});

it('should download the correct sha256 sum', async () => {
const expectedSum = '8629ccc47ee8d4dfe6d23efb93b293948a088a936180d07d3f2ed118f6dd64a5';

const remoteSum = await release.downloadSha256Sum(
release.builds[0].filename
);
assert.strictEqual(remoteSum, expectedSum);
});

it('should download the release', async () => {
const build = release.getBuild('darwin', 'amd64');
const tmpDir = tempy.directory();
const zipFile = path.resolve(tmpDir, `terraform-ls_v${release.version}.zip`);

await release.download(build.url, zipFile, 'js-releases/mocha-test');
await release.verify(zipFile, build.filename);

fs.rmSync(tmpDir, {
recursive: true
});
}).timeout(20 * 1000) // increase timeout for file download
let release: Release;

before(() => {
release = new Release({
name: 'terraform-ls',
version: '0.25.2',
shasums: 'terraform-ls_0.25.2_SHA256SUMS',
shasums_signature: 'terraform-ls_0.25.2_SHA256SUMS.sig',
shasums_signatures: ['terraform-ls_0.25.2_SHA256SUMS.72D7468F.sig', 'terraform-ls_0.25.2_SHA256SUMS.sig'],
builds: [
{
name: 'terraform-ls',
version: '0.25.2',
os: 'darwin',
arch: 'amd64',
filename: 'terraform-ls_0.25.2_darwin_amd64.zip',
url: 'https://releases.hashicorp.com/terraform-ls/0.25.2/terraform-ls_0.25.2_darwin_amd64.zip',
},
],
});
});

it('should calculate correct file sha256 sum', async () => {
const expectedSum = '0314c6a66b059bde92c5ed0f11601c144cbd916eff6d1241b5b44e076e5888dc';
const testPath = path.resolve(__dirname, '..', 'testFixture', 'shasumtest.txt');

const sum = await release.calculateFileSha256Sum(testPath);
assert.strictEqual(sum, expectedSum);
});

it('should download the correct sha256 sum', async () => {
const expectedSum = '8629ccc47ee8d4dfe6d23efb93b293948a088a936180d07d3f2ed118f6dd64a5';

const remoteSum = await release.downloadSha256Sum(release.builds[0].filename);
assert.strictEqual(remoteSum, expectedSum);
});

it('should download the release', async () => {
const build = release.getBuild('darwin', 'amd64');
const tmpDir = tempy.directory();
const zipFile = path.resolve(tmpDir, `terraform-ls_v${release.version}.zip`);

await release.download(build.url, zipFile, 'js-releases/mocha-test');
await release.verify(zipFile, build.filename);

fs.rmSync(tmpDir, {
recursive: true,
});
}).timeout(20 * 1000); // increase timeout for file download
});
Loading

0 comments on commit 6a48ccf

Please sign in to comment.