From c4a07cd1015061638ec6ac0af15ad4c88c8ea8fb Mon Sep 17 00:00:00 2001 From: Ryan Kienstra Date: Fri, 22 Apr 2022 20:13:19 -0500 Subject: [PATCH 01/12] Add a test for JobProvider::getChildren() --- src/classes/JobProvider.ts | 14 +++---- src/test/suite/classes/JobProvider.test.ts | 49 ++++++++++++++++++++++ 2 files changed, 56 insertions(+), 7 deletions(-) create mode 100644 src/test/suite/classes/JobProvider.test.ts diff --git a/src/classes/JobProvider.ts b/src/classes/JobProvider.ts index 16d2cecf..b8454af9 100644 --- a/src/classes/JobProvider.ts +++ b/src/classes/JobProvider.ts @@ -41,15 +41,15 @@ export default class JobProvider readonly onDidChangeTreeData: vscode.Event = this._onDidChangeTreeData.event; private jobs: string[] = []; - private jobErrorType: JobError | undefined; - private jobErrorMessage: string | undefined; - private runningJob: string | undefined; - private jobDependencies: Map | undefined; + private jobErrorType?: JobError; + private jobErrorMessage?: string; + private runningJob?: string; private logs: Record = {}; constructor( private readonly context: vscode.ExtensionContext, - private readonly reporter: TelemetryReporter + private readonly reporter: TelemetryReporter, + private jobDependencies?: Map ) {} async init() { @@ -162,7 +162,7 @@ export default class JobProvider return treeItem; } - getChildren(parentElement: Job | Log): vscode.TreeItem[] { + getChildren(parentElement?: Job | Log): Array { if (!parentElement) { return this.jobs.length ? this.getJobTreeItems( @@ -217,7 +217,7 @@ export default class JobProvider ); } - getErrorTreeItems(): vscode.TreeItem[] { + getErrorTreeItems(): Array { const errorMessage = this.getJobErrorMessage(); switch (this.jobErrorType) { diff --git a/src/test/suite/classes/JobProvider.test.ts b/src/test/suite/classes/JobProvider.test.ts new file mode 100644 index 00000000..5f1cf268 --- /dev/null +++ b/src/test/suite/classes/JobProvider.test.ts @@ -0,0 +1,49 @@ +import * as assert from 'assert'; +import * as vscode from 'vscode'; +import { Substitute } from '@fluffy-spoon/substitute'; +import TelemetryReporter from '@vscode/extension-telemetry'; +import JobProvider from '../../../classes/JobProvider'; +import Job from '../../../classes/Job'; + +suite('JobProvider', () => { + test('No element passed', () => { + const context = Substitute.for(); + const reporter = Substitute.for(); + + assert.deepStrictEqual( + [], + new JobProvider(context, reporter).getChildren() + ); + }); + + test('No child', () => { + const context = Substitute.for(); + const reporter = Substitute.for(); + + assert.deepStrictEqual( + [], + new JobProvider(context, reporter).getChildren( + new Job('foo', false, false) + ) + ); + }); + + test('Two children', () => { + const allJobs = new Map(); + allJobs.set('foo', []); + allJobs.set('baz', ['foo']); + allJobs.set('example', ['foo']); + + const jobProvider = new JobProvider( + Substitute.for(), + Substitute.for(), + allJobs + ); + + const children = jobProvider.getChildren(new Job('foo', false, false)); + assert.strictEqual(2, children.length); + + assert.strictEqual('baz', (children[0] as Job)?.getJobName()); + assert.strictEqual('example', (children[1] as Job)?.getJobName()); + }); +}); From d9a51692458cbff0ffe6043dc763733d8e70ad20 Mon Sep 17 00:00:00 2001 From: Ryan Kienstra Date: Fri, 22 Apr 2022 20:19:37 -0500 Subject: [PATCH 02/12] Extract stubs into a single function --- src/test/suite/classes/JobProvider.test.ts | 28 ++++++++-------------- 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/src/test/suite/classes/JobProvider.test.ts b/src/test/suite/classes/JobProvider.test.ts index 5f1cf268..bb2f0a35 100644 --- a/src/test/suite/classes/JobProvider.test.ts +++ b/src/test/suite/classes/JobProvider.test.ts @@ -5,26 +5,22 @@ import TelemetryReporter from '@vscode/extension-telemetry'; import JobProvider from '../../../classes/JobProvider'; import Job from '../../../classes/Job'; +function getStubs(): [vscode.ExtensionContext, TelemetryReporter] { + return [ + Substitute.for(), + Substitute.for(), + ]; +} + suite('JobProvider', () => { test('No element passed', () => { - const context = Substitute.for(); - const reporter = Substitute.for(); - - assert.deepStrictEqual( - [], - new JobProvider(context, reporter).getChildren() - ); + assert.deepStrictEqual([], new JobProvider(...getStubs()).getChildren()); }); test('No child', () => { - const context = Substitute.for(); - const reporter = Substitute.for(); - assert.deepStrictEqual( [], - new JobProvider(context, reporter).getChildren( - new Job('foo', false, false) - ) + new JobProvider(...getStubs()).getChildren(new Job('foo', false, false)) ); }); @@ -34,11 +30,7 @@ suite('JobProvider', () => { allJobs.set('baz', ['foo']); allJobs.set('example', ['foo']); - const jobProvider = new JobProvider( - Substitute.for(), - Substitute.for(), - allJobs - ); + const jobProvider = new JobProvider(...getStubs(), allJobs); const children = jobProvider.getChildren(new Job('foo', false, false)); assert.strictEqual(2, children.length); From 2cff9ccd950640c174d245f6464ea62b9fe4a9e9 Mon Sep 17 00:00:00 2001 From: Ryan Kienstra Date: Fri, 22 Apr 2022 20:39:12 -0500 Subject: [PATCH 03/12] Add a unit test file for Job --- src/test/suite/classes/Job.test.ts | 39 ++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 src/test/suite/classes/Job.test.ts diff --git a/src/test/suite/classes/Job.test.ts b/src/test/suite/classes/Job.test.ts new file mode 100644 index 00000000..6988cf60 --- /dev/null +++ b/src/test/suite/classes/Job.test.ts @@ -0,0 +1,39 @@ +import * as assert from 'assert'; +import * as vscode from 'vscode'; +import Job from '../../../classes/Job'; + +suite('Job', () => { + test('No element passed', () => { + const jobName = 'this-is-your-job'; + assert.strictEqual(jobName, new Job(jobName, false, false).getJobName()); + }); + + test('Is running', () => { + assert.strictEqual( + undefined, + new Job('example-job', false, false).contextValue + ); + assert.strictEqual( + 'isRunning', + new Job('example-job', true, false).contextValue + ); + }); + + test('Is success', () => { + const job = new Job('example', false, false); + job.setIsSuccess(); + assert.strictEqual('✅', job.description); + + job.setIsFailure(); + assert.strictEqual('❌', job.description); + }); + + test('Is expanded', () => { + const job = new Job('example', false, false); + job.setExpanded(); + assert.strictEqual( + vscode.TreeItemCollapsibleState.Expanded, + job.collapsibleState + ); + }); +}); From 7dc5482e9f83c069a243a27cab186756459f6e1b Mon Sep 17 00:00:00 2001 From: Ryan Kienstra Date: Fri, 22 Apr 2022 20:42:31 -0500 Subject: [PATCH 04/12] Add more types to getChildren() --- src/classes/JobProvider.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/classes/JobProvider.ts b/src/classes/JobProvider.ts index b8454af9..f7f80c50 100644 --- a/src/classes/JobProvider.ts +++ b/src/classes/JobProvider.ts @@ -162,7 +162,9 @@ export default class JobProvider return treeItem; } - getChildren(parentElement?: Job | Log): Array { + getChildren( + parentElement?: Job | Log + ): Array { if (!parentElement) { return this.jobs.length ? this.getJobTreeItems( From 7581c939afaf4ec47e1a4b000364b4dd680a1622 Mon Sep 17 00:00:00 2001 From: Ryan Kienstra Date: Fri, 22 Apr 2022 20:53:25 -0500 Subject: [PATCH 05/12] Remove the boilerplate extension test, which this isn't using --- src/test/suite/extension.test.ts | 15 --------------- 1 file changed, 15 deletions(-) delete mode 100644 src/test/suite/extension.test.ts diff --git a/src/test/suite/extension.test.ts b/src/test/suite/extension.test.ts deleted file mode 100644 index 17e2eab2..00000000 --- a/src/test/suite/extension.test.ts +++ /dev/null @@ -1,15 +0,0 @@ -import * as assert from 'assert'; - -// You can import and use all API from the 'vscode' module -// as well as import your extension to test it -import * as vscode from 'vscode'; -// import * as myExtension from '../../extension'; - -suite('Extension Test Suite', () => { - vscode.window.showInformationMessage('Start all tests.'); - - test('Sample test', () => { - assert.strictEqual(-1, [1, 2, 3].indexOf(5)); - assert.strictEqual(-1, [1, 2, 3].indexOf(0)); - }); -}); From 2191325f31f7dfbfc2d18064069a54fb29580999 Mon Sep 17 00:00:00 2001 From: Ryan Kienstra Date: Sun, 1 May 2022 14:21:14 -0500 Subject: [PATCH 06/12] Bump the free preview from 5 to 15 days --- README.md | 4 ++-- package.json | 2 +- src/constants/index.ts | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 61e36bf0..2cd725d6 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -[![5 day free preview](https://img.shields.io/badge/trial-5%20day-orange)](https://getlocalci.com/pricing/?utm_medium=extension&utm_source=readme) +[![15 day free preview](https://img.shields.io/badge/trial-15%20day-orange)](https://getlocalci.com/pricing/?utm_medium=extension&utm_source=readme) [![Buy license key](https://img.shields.io/badge/%24-paid-orange)](https://getlocalci.com/pricing/?utm_medium=extension&utm_source=readme) [![Platform: macOS](https://img.shields.io/badge/platform-macOS-yellow)](https://en.wikipedia.org/wiki/MacOS) [![Requires CircleCI®](https://img.shields.io/badge/requires-CirlcleCI%C2%AE-yellow)](https://circleci.com/docs/2.0/first-steps/) @@ -53,7 +53,7 @@ Find out in seconds whether the setup is right, all in your local. Local CI requires a [license key](https://getlocalci.com/pricing/?utm_medium=extension&utm_source=readme) for $10 per month. -But first you'll get a free 5-day preview, no sign-up or credit card needed. +But first you'll get a free 15-day preview, no sign-up or credit card needed. ## Requirements diff --git a/package.json b/package.json index ab4f0b07..5baf6b4e 100644 --- a/package.json +++ b/package.json @@ -237,7 +237,7 @@ }, "badges": [ { - "url": "https://img.shields.io/badge/trial-5%20day-orange", + "url": "https://img.shields.io/badge/trial-15%20day-orange", "href": "https://getlocalci.com/pricing/?utm_medium=extension&utm_source=badge", "description": "5 day free preview" }, diff --git a/src/constants/index.ts b/src/constants/index.ts index cfad3218..c2c8d509 100644 --- a/src/constants/index.ts +++ b/src/constants/index.ts @@ -40,7 +40,7 @@ export const LICENSE_KEY = 'local-ci.license.key'; export const LICENSE_VALIDITY = 'local-ci.license.validity'; export const LICENSE_VALIDITY_CACHE_EXPIRATION = 'local-ci.license.cache.expiration'; -export const TRIAL_LENGTH_IN_MILLISECONDS = 432000000; // 5 days. +export const TRIAL_LENGTH_IN_MILLISECONDS = 1296000000; // 15 days. export const EXTENDED_TRIAL_LENGTH_IN_MILLISECONDS = 1296000000; // 15 days. export const HAS_EXTENDED_TRIAL = 'local-ci.license.trial-extended.survey'; export const TRIAL_STARTED_TIMESTAMP = From f528879fb06dce815e870a72699e6baa6cbdd471 Mon Sep 17 00:00:00 2001 From: Ryan Kienstra Date: Sun, 1 May 2022 14:28:29 -0500 Subject: [PATCH 07/12] Fix failing unit tests from bumping trial length --- .../getMillisecondsRemainingInTrial.test.ts | 8 ++++---- src/test/suite/utils/isTrialExpired.test.ts | 20 +++++++++---------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/test/suite/utils/getMillisecondsRemainingInTrial.test.ts b/src/test/suite/utils/getMillisecondsRemainingInTrial.test.ts index 7e1ce8c1..a284aa2b 100644 --- a/src/test/suite/utils/getMillisecondsRemainingInTrial.test.ts +++ b/src/test/suite/utils/getMillisecondsRemainingInTrial.test.ts @@ -14,7 +14,7 @@ suite('getMillisecondsRemainingInTrial', () => { ); }); - test('4 days remaining', () => { + test('1 day remaining', () => { const time = new Date().getTime(); assert.strictEqual( getMillisecondsRemainingInTrial( @@ -22,7 +22,7 @@ suite('getMillisecondsRemainingInTrial', () => { time - 24 * hourInMilliseconds, TRIAL_LENGTH_IN_MILLISECONDS ), - 4 * dayInMilliseconds + 14 * dayInMilliseconds ); }); @@ -31,7 +31,7 @@ suite('getMillisecondsRemainingInTrial', () => { assert.strictEqual( getMillisecondsRemainingInTrial( time, - time - (4 * dayInMilliseconds + 23 * hourInMilliseconds), + time - (14 * dayInMilliseconds + 23 * hourInMilliseconds), TRIAL_LENGTH_IN_MILLISECONDS ), hourInMilliseconds @@ -43,7 +43,7 @@ suite('getMillisecondsRemainingInTrial', () => { assert.strictEqual( getMillisecondsRemainingInTrial( time, - time - 5 * dayInMilliseconds, + time - 15 * dayInMilliseconds, TRIAL_LENGTH_IN_MILLISECONDS ), 0 diff --git a/src/test/suite/utils/isTrialExpired.test.ts b/src/test/suite/utils/isTrialExpired.test.ts index 393e76ac..9d12f6d9 100644 --- a/src/test/suite/utils/isTrialExpired.test.ts +++ b/src/test/suite/utils/isTrialExpired.test.ts @@ -23,20 +23,20 @@ suite('isTrialExpired', () => { ); }); - test('preview began 5 days and 1 millisecond ago', () => { + test('preview barely expired', () => { assert.strictEqual( isTrialExpired( - new Date().getTime() - (5 * dayInMilliseconds + 1), + new Date().getTime() - (15 * dayInMilliseconds + 1), TRIAL_LENGTH_IN_MILLISECONDS ), true ); }); - test('preview began a week ago', () => { + test('trial expired by 2 days', () => { assert.strictEqual( isTrialExpired( - new Date().getTime() - 7 * dayInMilliseconds, + new Date().getTime() - 17 * dayInMilliseconds, TRIAL_LENGTH_IN_MILLISECONDS ), true @@ -50,30 +50,30 @@ suite('isTrialExpired', () => { ); }); - test('preview began 5 days and 10 milliseconds ago and was extended', () => { + test('preview began 15 days and 10 milliseconds ago and was extended', () => { assert.strictEqual( isTrialExpired( - new Date().getTime() - (5 * dayInMilliseconds + 10), + new Date().getTime() - (15 * dayInMilliseconds + 10), extendedTrial ), false ); }); - test('preview began a week ago and was extended', () => { + test('preview 17 days ago and was extended', () => { assert.strictEqual( isTrialExpired( - new Date().getTime() - 7 * dayInMilliseconds, + new Date().getTime() - 17 * dayInMilliseconds, extendedTrial ), false ); }); - test('preview began 20 days and 1 millisecond ago and was extended', () => { + test('preview began 30 days and 1 millisecond ago and was extended', () => { assert.strictEqual( isTrialExpired( - new Date().getTime() - 20 * dayInMilliseconds, + new Date().getTime() - 30 * dayInMilliseconds, extendedTrial ), true From 843e72f9fda4b9d4c4f819d8331746757ac32169 Mon Sep 17 00:00:00 2001 From: Ryan Kienstra Date: Sun, 1 May 2022 14:30:31 -0500 Subject: [PATCH 08/12] Fix the description of a badge --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 5baf6b4e..e7b85cd5 100644 --- a/package.json +++ b/package.json @@ -239,7 +239,7 @@ { "url": "https://img.shields.io/badge/trial-15%20day-orange", "href": "https://getlocalci.com/pricing/?utm_medium=extension&utm_source=badge", - "description": "5 day free preview" + "description": "15 day free preview" }, { "url": "https://img.shields.io/badge/%24-paid-orange", From 11b28d7ce6166680ac562fef32acf79bed20f759 Mon Sep 17 00:00:00 2001 From: Ryan Kienstra Date: Sun, 1 May 2022 14:31:34 -0500 Subject: [PATCH 09/12] Fix the description of a test --- src/test/suite/utils/isTrialExpired.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/suite/utils/isTrialExpired.test.ts b/src/test/suite/utils/isTrialExpired.test.ts index 9d12f6d9..86dceb06 100644 --- a/src/test/suite/utils/isTrialExpired.test.ts +++ b/src/test/suite/utils/isTrialExpired.test.ts @@ -60,7 +60,7 @@ suite('isTrialExpired', () => { ); }); - test('preview 17 days ago and was extended', () => { + test('preview began 17 days ago and was extended', () => { assert.strictEqual( isTrialExpired( new Date().getTime() - 17 * dayInMilliseconds, From d382424e7d1bb39ce8c3b354fe13019cab77bd05 Mon Sep 17 00:00:00 2001 From: Ryan Kienstra Date: Sun, 1 May 2022 14:43:59 -0500 Subject: [PATCH 10/12] Move the paid badge to the beginning --- README.md | 2 +- package.json | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 2cd725d6..27deaa17 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ -[![15 day free preview](https://img.shields.io/badge/trial-15%20day-orange)](https://getlocalci.com/pricing/?utm_medium=extension&utm_source=readme) [![Buy license key](https://img.shields.io/badge/%24-paid-orange)](https://getlocalci.com/pricing/?utm_medium=extension&utm_source=readme) +[![15 day free preview](https://img.shields.io/badge/trial-15%20day-orange)](https://getlocalci.com/pricing/?utm_medium=extension&utm_source=readme) [![Platform: macOS](https://img.shields.io/badge/platform-macOS-yellow)](https://en.wikipedia.org/wiki/MacOS) [![Requires CircleCI®](https://img.shields.io/badge/requires-CirlcleCI%C2%AE-yellow)](https://circleci.com/docs/2.0/first-steps/) diff --git a/package.json b/package.json index e7b85cd5..c81c3f7c 100644 --- a/package.json +++ b/package.json @@ -237,14 +237,14 @@ }, "badges": [ { - "url": "https://img.shields.io/badge/trial-15%20day-orange", + "url": "https://img.shields.io/badge/%24-paid-orange", "href": "https://getlocalci.com/pricing/?utm_medium=extension&utm_source=badge", - "description": "15 day free preview" + "description": "Buy license key" }, { - "url": "https://img.shields.io/badge/%24-paid-orange", + "url": "https://img.shields.io/badge/trial-15%20day-orange", "href": "https://getlocalci.com/pricing/?utm_medium=extension&utm_source=badge", - "description": "Buy license key" + "description": "15 day free preview" }, { "url": "https://vsmarketplacebadge.apphb.com/trending-monthly/LocalCI.local-ci.svg?logo=tinder&color=orange&logoColor=white&label=trending%20monthly", From 6f9d962ef8482e740a31616a2824242b3812372a Mon Sep 17 00:00:00 2001 From: Ryan Kienstra Date: Sun, 1 May 2022 15:27:02 -0500 Subject: [PATCH 11/12] Ignore an eslint rule prohibiting control characters --- src/utils/listenToJob.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils/listenToJob.ts b/src/utils/listenToJob.ts index 4ff6e48c..fb0d07b5 100644 --- a/src/utils/listenToJob.ts +++ b/src/utils/listenToJob.ts @@ -77,7 +77,7 @@ export default function listenToJob( return; } - fs.appendFileSync(logFilePath, output); + fs.appendFileSync(logFilePath, output.replace(/\[[0-9]+m/g, '')); // eslint-disable-line no-control-regex // This should be the final 'Success!' message when a job succeeds. // There are a lot of other 'Success!' messages that might trigger this incorrectly. From 4de1d7512109e5ed4996fe50edda0f80c52bee9a Mon Sep 17 00:00:00 2001 From: Ryan Kienstra Date: Sun, 1 May 2022 15:38:02 -0500 Subject: [PATCH 12/12] Add a comment that this removes the terminal encoding --- src/utils/listenToJob.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/utils/listenToJob.ts b/src/utils/listenToJob.ts index fb0d07b5..0a9d5bf1 100644 --- a/src/utils/listenToJob.ts +++ b/src/utils/listenToJob.ts @@ -77,7 +77,13 @@ export default function listenToJob( return; } - fs.appendFileSync(logFilePath, output.replace(/\[[0-9]+m/g, '')); // eslint-disable-line no-control-regex + fs.appendFileSync( + logFilePath, + // Remove terminal color encoding, like  + // Convert this: Success! + // To: Success! + output.replace(/\[[0-9]+m/g, '') // eslint-disable-line no-control-regex + ); // This should be the final 'Success!' message when a job succeeds. // There are a lot of other 'Success!' messages that might trigger this incorrectly.