diff --git a/test/extension.test.ts b/test/extension.test.ts new file mode 100644 index 00000000..1f248602 --- /dev/null +++ b/test/extension.test.ts @@ -0,0 +1,3 @@ +describe("PragmaUtil", () => { + require("./pragmaUtil"); +}); diff --git a/test/index.js b/test/index.js deleted file mode 100644 index a5874a69..00000000 --- a/test/index.js +++ /dev/null @@ -1,8 +0,0 @@ -const chai = require("chai") -const expect = chai.expect - -global.expect = expect - -describe('PragmaUtil', () => { - require('./pragmaUtil') -}) \ No newline at end of file diff --git a/test/index.ts b/test/index.ts index e69de29b..abb2dd76 100644 --- a/test/index.ts +++ b/test/index.ts @@ -0,0 +1,8 @@ +import * as testRunner from "vscode/lib/testrunner"; + +testRunner.configure({ + ui: "bdd", + useColors: true, + timeout: 5000 +}); +module.exports = testRunner; diff --git a/test/pragmaUtil/index.js b/test/pragmaUtil/index.js deleted file mode 100644 index 8564c430..00000000 --- a/test/pragmaUtil/index.js +++ /dev/null @@ -1,72 +0,0 @@ -const fs = require('fs') -const expect = require('chai').expect - -let test_settings = null - -const OSTypes = require('../../out/src/enums').OsType -const PragmaUtil = require('../../out/src/pragmaUtil').default - -describe('Process before upload', function () { - this.beforeAll(() => { - test_settings = fs.readFileSync(__dirname + '/testSettings.json', 'utf8') - }) - - it('should remove @sync-ignore and @sync ignore lines', () => { - expect(PragmaUtil.removeIgnoreBlocks(test_settings)).to.not.contains('@sync-ignore').and.not.contains('@sync ignore') - }) - - it('should trim os, host and env', () => { - expect(PragmaUtil.processBeforeUpload(test_settings)).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(/\t"mac"/) - }) - - it('should get eight @sync pragma valid lines', () => { - const processed = PragmaUtil.processBeforeUpload(test_settings) - 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, OSTypes['Linux'], null) - expect(processed).to.match(/\s+"linux"/).and.to.match(/.+\/\/\s+"mac"/) - }) - - it('should not comment os=linux settings lines', () => { - let processed = PragmaUtil.processBeforeUpload(test_settings) - processed = PragmaUtil.processBeforeWrite(processed, OSTypes['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(test_settings) - process.env["TEST_ENV"] = true - expect(PragmaUtil.processBeforeWrite(processed, OSTypes['Mac'], 'mac2')).to.match(/\n\s+"mac2"/).and.match(/\n\s+"mactest"/) - }) -}) \ No newline at end of file diff --git a/test/pragmaUtil/index.ts b/test/pragmaUtil/index.ts new file mode 100644 index 00000000..36dce643 --- /dev/null +++ b/test/pragmaUtil/index.ts @@ -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(); + }); +});