Skip to content

Commit

Permalink
Adding VS Code tests in typescript. Run test changing launch mode to …
Browse files Browse the repository at this point in the history
…"Launch Test". Remove javascript files.
  • Loading branch information
protiumx authored and shanalikhan committed Oct 9, 2018
1 parent c1f03c2 commit 2b0a3b9
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 80 deletions.
3 changes: 3 additions & 0 deletions test/extension.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
describe("PragmaUtil", () => {
require("./pragmaUtil");
});
8 changes: 0 additions & 8 deletions test/index.js

This file was deleted.

8 changes: 8 additions & 0 deletions test/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import * as testRunner from "vscode/lib/testrunner";

testRunner.configure({
ui: "bdd",
useColors: true,
timeout: 5000
});
module.exports = testRunner;
72 changes: 0 additions & 72 deletions test/pragmaUtil/index.js

This file was deleted.

92 changes: 92 additions & 0 deletions test/pragmaUtil/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
import { expect } from "chai";
import fs = require("fs");
import { OsType } from "../../src/enums";
import PragmaUtil from "../../src/pragmaUtil";

let testSettings = null;

describe("Process before upload", function() {
this.beforeAll(() => {
testSettings = fs.readFileSync(
__dirname + "/../../../test/pragmaUtil/testSettings.json",
"utf8"
);
});

it("should remove @sync-ignore and @sync ignore lines", () => {
expect(PragmaUtil.removeIgnoreBlocks(testSettings))
.to.not.contains("@sync-ignore")
.and.not.contains("@sync ignore");
});

it("should trim os, host and env", () => {
expect(PragmaUtil.processBeforeUpload(testSettings)).to.match(
/@sync os=linux host=trim env=TEST_ENV/
);
});

it("should comment line after linebreak", () => {
const line = '// @sync host=mac1 os=_mac_\n\t"mac": 3,';
expect(PragmaUtil.commentLineAfterBreak(line)).to.match(/\/\/\s*"mac"/);
});

it("should uncomment line after linebreak", () => {
const line = '// @sync host=mac1 os=_mac_\n\t//"mac": 3,';
expect(PragmaUtil.uncommentLineAfterBreak(line)).to.match(/\s*"mac"/);
});

it("should get eight @sync pragma valid lines", () => {
const processed = PragmaUtil.processBeforeUpload(testSettings);
expect(PragmaUtil.matchPragmaSettings(processed).length).to.be.equals(8);
});

it("should uncomment all lines", () => {
const commentedSettings = `
// @sync os=linux
// "window": 1,
// @sync os=mac
// "mac": 1
`;

expect(PragmaUtil.processBeforeUpload(commentedSettings))
.to.match(/\s+"window"/)
.and.to.match(/\s+"mac"/);
});

it("should uncomment lines before write file for os=linux", () => {
const commentedSettings = `{
// @sync os=linux
// "linux": 1,
// @sync os=mac
"mac": 1
}`;
const processed = PragmaUtil.processBeforeWrite(
commentedSettings,
OsType.Linux,
null
);
expect(processed)
.to.match(/\s+"linux"/)
.and.to.match(/.+\/\/"mac"/);
});

it("should not comment os=linux settings lines", () => {
let processed = PragmaUtil.processBeforeUpload(testSettings);
processed = PragmaUtil.processBeforeWrite(processed, OsType.Linux, null);
expect(processed).to.match(/\s+"not_commented"/);
});

it("should leave only settings that matches with os=mac host=mac2 env=TEST_ENV", () => {
const processed = PragmaUtil.processBeforeUpload(testSettings);
// tslint:disable-next-line:no-string-literal
process.env["TEST_ENV"] = "1";
expect(PragmaUtil.processBeforeWrite(processed, OsType.Mac, "mac2"))
.to.match(/\n\s+"mac2"/)
.and.match(/\n\s+"mactest"/);
});

it("should remove all comments and parse JSON", () => {
const possibleJson = PragmaUtil.removeAllComments(testSettings);
expect(JSON.parse.bind(null, possibleJson)).to.not.throw();
});
});

0 comments on commit 2b0a3b9

Please sign in to comment.