From 6ff89c8a36290583fb140eafa94d56875627f535 Mon Sep 17 00:00:00 2001 From: Jason Rogers Date: Wed, 2 Jan 2019 22:20:18 -0500 Subject: [PATCH] Configure CircleCI and Add Basic Tests (#72) * Change docker images to get all dependencies for tests automatically * Restore correct working directory * Add tests for vscode-langserver-sms * Add basic tests for sparql language server client * Add tests for Turtle language server client * Force extensions to find their nearby extensionDepdendency --- .circleci/config.yml | 26 ++-- .../fixtures/bad/expect-json-sql-graphql.sms | 1 + .../fixtures/good/minimal-mapping.sms | 1 + vscode-langserver-sms/out/extension.js | 2 +- vscode-langserver-sms/out/extension.js.map | 2 +- .../out/test/extension.test.js | 67 ++++++--- .../out/test/extension.test.js.map | 2 +- vscode-langserver-sms/out/test/index.js | 5 +- vscode-langserver-sms/out/test/index.js.map | 2 +- vscode-langserver-sms/package.json | 8 +- vscode-langserver-sms/scripts/e2e-tests.sh | 7 + vscode-langserver-sms/src/extension.ts | 4 +- .../src/test/extension.test.ts | 90 +++++++++--- vscode-langserver-sms/src/test/index.ts | 9 +- vscode-langserver-sms/yarn.lock | 49 +++++++ .../fixtures/bad/basic-bad-select.sparql | 5 + .../out/test/extension.test.js | 126 ++++++++++++++--- .../out/test/extension.test.js.map | 2 +- vscode-langserver-sparql/out/test/index.js | 5 +- .../out/test/index.js.map | 2 +- vscode-langserver-sparql/package.json | 8 +- vscode-langserver-sparql/scripts/e2e-tests.sh | 7 + .../src/test/extension.test.ts | 133 +++++++++++++++--- vscode-langserver-sparql/src/test/index.ts | 9 +- vscode-langserver-sparql/yarn.lock | 49 +++++++ .../fixtures/bad/basic-bad-turtle.ttl | 1 + .../out/test/extension.test.js | 86 ++++++++--- .../out/test/extension.test.js.map | 2 +- vscode-langserver-turtle/out/test/index.js | 5 +- .../out/test/index.js.map | 2 +- vscode-langserver-turtle/package.json | 8 +- vscode-langserver-turtle/scripts/e2e-tests.sh | 7 + .../src/test/extension.test.ts | 90 +++++++++--- vscode-langserver-turtle/src/test/index.ts | 9 +- vscode-langserver-turtle/yarn.lock | 49 +++++++ 35 files changed, 731 insertions(+), 149 deletions(-) create mode 100644 vscode-langserver-sms/fixtures/bad/expect-json-sql-graphql.sms create mode 100644 vscode-langserver-sms/fixtures/good/minimal-mapping.sms create mode 100644 vscode-langserver-sms/scripts/e2e-tests.sh create mode 100644 vscode-langserver-sparql/fixtures/bad/basic-bad-select.sparql create mode 100644 vscode-langserver-sparql/scripts/e2e-tests.sh create mode 100644 vscode-langserver-turtle/fixtures/bad/basic-bad-turtle.ttl create mode 100644 vscode-langserver-turtle/scripts/e2e-tests.sh diff --git a/.circleci/config.yml b/.circleci/config.yml index d31fcff..da5e077 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1,15 +1,13 @@ version: 2 +references: + working_directory: &working_directory ~/stardog-vsc jobs: build: docker: - - image: circleci/node:8.9-stretch + - image: circleci/node:8.9-stretch-browsers + working_directory: *working_directory steps: - checkout - - run: - name: Install OS-level Dependencies - command: | - sudo apt-get update - sudo apt-get install -y libgtk-3-0 --no-install-recommends - restore_cache: # This caching strategy isn't ideal, but CircleCI's current support for monorepos is poor, and this works well enough keys: @@ -20,9 +18,9 @@ jobs: - run: name: Install Node Modules command: | - pushd ./vscode-langserver-sms && yarn && popd - pushd ./vscode-langserver-sparql && yarn && popd - pushd ./vscode-langserver-turtle && yarn && popd + cd ~/stardog-vsc/vscode-langserver-sms && yarn + cd ~/stardog-vsc/vscode-langserver-sparql && yarn + cd ~/stardog-vsc/vscode-langserver-turtle && yarn - save_cache: key: dependency-cache-{{ .Environment.CACHE_VERSION }}-{{ .Branch }}-{{ checksum "./vscode-langserver-sms/yarn.lock" }}-{{ checksum "./vscode-langserver-sparql/yarn.lock" }}-{{ checksum "./vscode-langserver-turtle/yarn.lock" }} paths: @@ -36,16 +34,18 @@ jobs: test: docker: - - image: circleci/node:8.9-stretch + - image: circleci/node:8.9-stretch-browsers + working_directory: *working_directory steps: - attach_workspace: at: . - run: name: Tests command: | - pushd ./vscode-langserver-sms && yarn test && popd - pushd ./vscode-langserver-sparql && yarn test && popd - pushd ./vscode-langserver-turtle && yarn test && popd + cp -R ~/stardog-vsc/stardog-rdf-grammars ~/stardog-vsc/stardog-union.stardog-rdf-grammars + cd ~/stardog-vsc/vscode-langserver-sms && yarn run test + cd ~/stardog-vsc/vscode-langserver-sparql && yarn run test + cd ~/stardog-vsc/vscode-langserver-turtle && yarn run test workflows: version: 2 diff --git a/vscode-langserver-sms/fixtures/bad/expect-json-sql-graphql.sms b/vscode-langserver-sms/fixtures/bad/expect-json-sql-graphql.sms new file mode 100644 index 0000000..06c8ad1 --- /dev/null +++ b/vscode-langserver-sms/fixtures/bad/expect-json-sql-graphql.sms @@ -0,0 +1 @@ +mapping from \ No newline at end of file diff --git a/vscode-langserver-sms/fixtures/good/minimal-mapping.sms b/vscode-langserver-sms/fixtures/good/minimal-mapping.sms new file mode 100644 index 0000000..e63d4f4 --- /dev/null +++ b/vscode-langserver-sms/fixtures/good/minimal-mapping.sms @@ -0,0 +1 @@ +mapping from json {} to {} where {} \ No newline at end of file diff --git a/vscode-langserver-sms/out/extension.js b/vscode-langserver-sms/out/extension.js index 976a2ec..c468bae 100644 --- a/vscode-langserver-sms/out/extension.js +++ b/vscode-langserver-sms/out/extension.js @@ -4,7 +4,7 @@ const path = require("path"); const vscode_languageclient_1 = require("vscode-languageclient"); let client; function activate(context) { - const server = context.asAbsolutePath(path.join("..", "stardog-language-servers", "packages", "sms-language-server", "dist", "cli.js")); + const server = context.asAbsolutePath(path.join("node_modules", "sms-language-server", "dist", "cli.js")); const baseServerOptions = { module: server, transport: vscode_languageclient_1.TransportKind.stdio, diff --git a/vscode-langserver-sms/out/extension.js.map b/vscode-langserver-sms/out/extension.js.map index 43cb8ac..807f27a 100644 --- a/vscode-langserver-sms/out/extension.js.map +++ b/vscode-langserver-sms/out/extension.js.map @@ -1 +1 @@ -{"version":3,"file":"extension.js","sourceRoot":"","sources":["../src/extension.ts"],"names":[],"mappings":";;AAAA,6BAA6B;AAE7B,iEAM+B;AAE/B,IAAI,MAAsB,CAAC;AAE3B,kBAAyB,OAAgC;IACvD,MAAM,MAAM,GAAG,OAAO,CAAC,cAAc,CACnC,IAAI,CAAC,IAAI,CACP,IAAI,EACJ,0BAA0B,EAC1B,UAAU,EACV,qBAAqB,EACrB,MAAM,EACN,QAAQ,CACT,CACF,CAAC;IACF,MAAM,iBAAiB,GAAe;QACpC,MAAM,EAAE,MAAM;QACd,SAAS,EAAE,qCAAa,CAAC,KAAK;QAC9B,IAAI,EAAE,CAAC,SAAS,CAAC;KAClB,CAAC;IACF,MAAM,aAAa,GAAkB;QACnC,GAAG,EAAE,iBAAiB;QACtB,KAAK,oBACA,iBAAiB;YACpB,wCAAwC;YACxC,OAAO,EAAE;gBACP,QAAQ,EAAE,CAAC,UAAU,EAAE,gBAAgB,CAAC;aACzC,GACF;KACF,CAAC;IACF,MAAM,aAAa,GAA0B;QAC3C,gBAAgB,EAAE;YAChB;gBACE,MAAM,EAAE,MAAM;gBACd,QAAQ,EAAE,KAAK;aAChB;YACD;gBACE,MAAM,EAAE,MAAM;gBACd,QAAQ,EAAE,wBAAwB;aACnC;SACF;KACF,CAAC;IAEF,MAAM,GAAG,IAAI,sCAAc,CACzB,0BAA0B,EAC1B,6BAA6B,EAC7B,aAAa,EACb,aAAa,CACd,CAAC;IAEF,MAAM,CAAC,KAAK,EAAE,CAAC;AACjB,CAAC;AA/CD,4BA+CC;AAED;IACE,IAAI,MAAM,EAAE;QACV,OAAO,MAAM,CAAC,IAAI,EAAE,CAAC;KACtB;AACH,CAAC;AAJD,gCAIC"} \ No newline at end of file +{"version":3,"file":"extension.js","sourceRoot":"","sources":["../src/extension.ts"],"names":[],"mappings":";;AAAA,6BAA6B;AAE7B,iEAM+B;AAE/B,IAAI,MAAsB,CAAC;AAE3B,kBAAyB,OAAgC;IACvD,MAAM,MAAM,GAAG,OAAO,CAAC,cAAc,CACnC,IAAI,CAAC,IAAI,CACP,cAAc,EACd,qBAAqB,EACrB,MAAM,EACN,QAAQ,CACT,CACF,CAAC;IACF,MAAM,iBAAiB,GAAe;QACpC,MAAM,EAAE,MAAM;QACd,SAAS,EAAE,qCAAa,CAAC,KAAK;QAC9B,IAAI,EAAE,CAAC,SAAS,CAAC;KAClB,CAAC;IACF,MAAM,aAAa,GAAkB;QACnC,GAAG,EAAE,iBAAiB;QACtB,KAAK,oBACA,iBAAiB;YACpB,wCAAwC;YACxC,OAAO,EAAE;gBACP,QAAQ,EAAE,CAAC,UAAU,EAAE,gBAAgB,CAAC;aACzC,GACF;KACF,CAAC;IACF,MAAM,aAAa,GAA0B;QAC3C,gBAAgB,EAAE;YAChB;gBACE,MAAM,EAAE,MAAM;gBACd,QAAQ,EAAE,KAAK;aAChB;YACD;gBACE,MAAM,EAAE,MAAM;gBACd,QAAQ,EAAE,wBAAwB;aACnC;SACF;KACF,CAAC;IAEF,MAAM,GAAG,IAAI,sCAAc,CACzB,0BAA0B,EAC1B,6BAA6B,EAC7B,aAAa,EACb,aAAa,CACd,CAAC;IAEF,MAAM,CAAC,KAAK,EAAE,CAAC;AACjB,CAAC;AA7CD,4BA6CC;AAED;IACE,IAAI,MAAM,EAAE;QACV,OAAO,MAAM,CAAC,IAAI,EAAE,CAAC;KACtB;AACH,CAAC;AAJD,gCAIC"} \ No newline at end of file diff --git a/vscode-langserver-sms/out/test/extension.test.js b/vscode-langserver-sms/out/test/extension.test.js index 2d35c9d..eae8e55 100644 --- a/vscode-langserver-sms/out/test/extension.test.js +++ b/vscode-langserver-sms/out/test/extension.test.js @@ -1,21 +1,56 @@ "use strict"; -// -// Note: This example test is leveraging the Mocha test framework. -// Please refer to their documentation on https://mochajs.org/ for help. -// +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; Object.defineProperty(exports, "__esModule", { value: true }); -// The module 'assert' provides assertion methods from node -const assert = require("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'; -// Defines a Mocha test suite to group tests of similar kind together -suite("Extension Tests", function () { - // Defines a Mocha unit test - test("Something 1", function () { - assert.equal(-1, [1, 2, 3].indexOf(5)); - assert.equal(-1, [1, 2, 3].indexOf(0)); +const chai_1 = require("chai"); +const path = require("path"); +const vscode = require("vscode"); +const sleep = (ms) => new Promise(resolve => setTimeout(resolve, ms)); +describe("SMS Language Server Extension", () => { + let docUri; + let document; + beforeEach(() => __awaiter(this, void 0, void 0, function* () { + const ext = vscode.extensions.getExtension("stardog-union.vscode-langserver-sms"); + yield ext.activate(); + docUri = vscode.Uri.file(path.join(__dirname, "..", "..", "fixtures", "bad", "expect-json-sql-graphql.sms")); + document = yield vscode.workspace.openTextDocument(docUri); + yield vscode.window.showTextDocument(document); + yield sleep(2000); // let server start + })); + afterEach(() => { + document = null; + }); + it("receives error diagnostics from the server", () => { + const receivedDiagnostics = vscode.languages.getDiagnostics(docUri); + const normalizedReceivedDiagnostics = JSON.parse(JSON.stringify(receivedDiagnostics)); + chai_1.expect(normalizedReceivedDiagnostics).to.eql([ + { + severity: "Error", + message: "\tExpected one of the following:\n Sql\n Json\n GraphQl", + range: [ + { + line: 0, + character: 13 + }, + { + line: 0, + character: 13 + } + ], + source: "FromClause" + } + ]); }); + it("receives hover help from the server", () => __awaiter(this, void 0, void 0, function* () { + const hoverHelp = (yield vscode.commands.executeCommand('vscode.executeHoverProvider', docUri, new vscode.Position(0, 0))); + console.log(JSON.stringify(hoverHelp, null, 2)); + return chai_1.expect(true).to.be.true; + })); }); //# sourceMappingURL=extension.test.js.map \ No newline at end of file diff --git a/vscode-langserver-sms/out/test/extension.test.js.map b/vscode-langserver-sms/out/test/extension.test.js.map index b4c6ac5..d783ad3 100644 --- a/vscode-langserver-sms/out/test/extension.test.js.map +++ b/vscode-langserver-sms/out/test/extension.test.js.map @@ -1 +1 @@ -{"version":3,"file":"extension.test.js","sourceRoot":"","sources":["../../src/test/extension.test.ts"],"names":[],"mappings":";AAAA,EAAE;AACF,kEAAkE;AAClE,wEAAwE;AACxE,EAAE;;AAEF,2DAA2D;AAC3D,iCAAiC;AAEjC,0DAA0D;AAC1D,8CAA8C;AAC9C,oCAAoC;AACpC,+CAA+C;AAE/C,qEAAqE;AACrE,KAAK,CAAC,iBAAiB,EAAE;IAErB,4BAA4B;IAC5B,IAAI,CAAC,aAAa,EAAE;QAChB,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;QACvC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;IAC3C,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"} \ No newline at end of file +{"version":3,"file":"extension.test.js","sourceRoot":"","sources":["../../src/test/extension.test.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,+BAA8B;AAC9B,6BAA6B;AAC7B,iCAAiC;AAEjC,MAAM,KAAK,GAAG,CAAC,EAAU,EAAE,EAAE,CAAC,IAAI,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,CAAC;AAE9E,QAAQ,CAAC,+BAA+B,EAAE,GAAG,EAAE;IAC7C,IAAI,MAAkB,CAAC;IACvB,IAAI,QAAoC,CAAC;IAEzC,UAAU,CAAC,GAAS,EAAE;QACpB,MAAM,GAAG,GAAG,MAAM,CAAC,UAAU,CAAC,YAAY,CAAC,qCAAqC,CAAE,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E,MAAM,EAAE,IAAI,MAAM,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAiB,CAAC;QAC3I,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;QAChD,OAAO,aAAM,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,IAAI,CAAC;IACjC,CAAC,CAAA,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"} \ No newline at end of file diff --git a/vscode-langserver-sms/out/test/index.js b/vscode-langserver-sms/out/test/index.js index 8cbe4a5..ed6ec92 100644 --- a/vscode-langserver-sms/out/test/index.js +++ b/vscode-langserver-sms/out/test/index.js @@ -15,8 +15,9 @@ const testRunner = require("vscode/lib/testrunner"); // You can directly control Mocha options by uncommenting the following lines // See https://github.com/mochajs/mocha/wiki/Using-mocha-programmatically#set-options for more info testRunner.configure({ - ui: 'tdd', - useColors: true // colored output from test results + ui: "bdd", + useColors: true, + timeout: 10000 // allow VSCode and server time to start }); module.exports = testRunner; //# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/vscode-langserver-sms/out/test/index.js.map b/vscode-langserver-sms/out/test/index.js.map index e288077..5a8d715 100644 --- a/vscode-langserver-sms/out/test/index.js.map +++ b/vscode-langserver-sms/out/test/index.js.map @@ -1 +1 @@ -{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/test/index.ts"],"names":[],"mappings":";AAAA,EAAE;AACF,mEAAmE;AACnE,EAAE;AACF,8EAA8E;AAC9E,oDAAoD;AACpD,EAAE;AACF,+EAA+E;AAC/E,kFAAkF;AAClF,iFAAiF;AACjF,gFAAgF;AAChF,oDAAoD;;AAEpD,oDAAoD;AAEpD,6EAA6E;AAC7E,mGAAmG;AACnG,UAAU,CAAC,SAAS,CAAC;IACjB,EAAE,EAAE,KAAK;IACT,SAAS,EAAE,IAAI,CAAC,mCAAmC;CACtD,CAAC,CAAC;AAEH,MAAM,CAAC,OAAO,GAAG,UAAU,CAAC"} \ No newline at end of file +{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/test/index.ts"],"names":[],"mappings":";AAAA,EAAE;AACF,mEAAmE;AACnE,EAAE;AACF,8EAA8E;AAC9E,oDAAoD;AACpD,EAAE;AACF,+EAA+E;AAC/E,kFAAkF;AAClF,iFAAiF;AACjF,gFAAgF;AAChF,oDAAoD;;AAEpD,oDAAoD;AAEpD,6EAA6E;AAC7E,mGAAmG;AACnG,UAAU,CAAC,SAAS,CAAC;IACnB,EAAE,EAAE,KAAK;IACT,SAAS,EAAE,IAAI;IACf,OAAO,EAAE,KAAK,CAAC,wCAAwC;CACxD,CAAC,CAAC;AAEH,MAAM,CAAC,OAAO,GAAG,UAAU,CAAC"} \ No newline at end of file diff --git a/vscode-langserver-sms/package.json b/vscode-langserver-sms/package.json index ac9ab50..8c2ac40 100644 --- a/vscode-langserver-sms/package.json +++ b/vscode-langserver-sms/package.json @@ -37,11 +37,13 @@ "compile": "tsc -p ./", "watch": "tsc -watch -p ./", "postinstall": "node ./node_modules/vscode/bin/install", - "test": "yarn run compile && node ./node_modules/vscode/bin/test" + "test": "yarn run compile && sh ./scripts/e2e-tests.sh" }, "devDependencies": { + "@types/chai": "^4.1.7", "@types/mocha": "^2.2.42", "@types/node": "^8.10.25", + "chai": "^4.2.0", "tslint": "^5.8.0", "typescript": "^2.6.1" }, @@ -50,5 +52,7 @@ "vscode": "^1.1.26", "vscode-languageclient": "^5.2.1" }, - "extensionDependencies": ["stardog-union.stardog-rdf-grammars"] + "extensionDependencies": [ + "stardog-union.stardog-rdf-grammars" + ] } diff --git a/vscode-langserver-sms/scripts/e2e-tests.sh b/vscode-langserver-sms/scripts/e2e-tests.sh new file mode 100644 index 0000000..aaa0261 --- /dev/null +++ b/vscode-langserver-sms/scripts/e2e-tests.sh @@ -0,0 +1,7 @@ +#!/usr/bin/env bash + +export CODE_TESTS_PATH="$(pwd)/out/test" +export CODE_TESTS_WORKSPACE="$(pwd)/fixtures" +export CODE_EXTENSIONS_PATH="$(pwd)/.." + +node "$(pwd)/node_modules/vscode/bin/test" diff --git a/vscode-langserver-sms/src/extension.ts b/vscode-langserver-sms/src/extension.ts index c30cedf..55ff37b 100644 --- a/vscode-langserver-sms/src/extension.ts +++ b/vscode-langserver-sms/src/extension.ts @@ -13,9 +13,7 @@ let client: LanguageClient; export function activate(context: vscode.ExtensionContext) { const server = context.asAbsolutePath( path.join( - "..", - "stardog-language-servers", - "packages", + "node_modules", "sms-language-server", "dist", "cli.js" diff --git a/vscode-langserver-sms/src/test/extension.test.ts b/vscode-langserver-sms/src/test/extension.test.ts index a7a297f..b5c4c36 100644 --- a/vscode-langserver-sms/src/test/extension.test.ts +++ b/vscode-langserver-sms/src/test/extension.test.ts @@ -1,22 +1,76 @@ -// -// Note: This example test is leveraging the Mocha test framework. -// Please refer to their documentation on https://mochajs.org/ for help. -// +import { expect } from "chai"; +import * as path from "path"; +import * as vscode from "vscode"; -// The module 'assert' provides assertion methods from node -import * as assert from 'assert'; +const sleep = (ms: number) => new Promise(resolve => setTimeout(resolve, ms)); -// 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'; +describe("SMS Language Server Extension", () => { + let docUri: vscode.Uri; + let document: vscode.TextDocument | null; -// Defines a Mocha test suite to group tests of similar kind together -suite("Extension Tests", function () { + beforeEach(async () => { + const ext = vscode.extensions.getExtension("stardog-union.vscode-langserver-sms")!; + await ext.activate(); + docUri = vscode.Uri.file( + path.join(__dirname, "..", "..", "fixtures", "bad", "expect-json-sql-graphql.sms") + ); + document = await vscode.workspace.openTextDocument(docUri); + await vscode.window.showTextDocument(document); + await sleep(2000); // let server start + }); - // Defines a Mocha unit test - test("Something 1", function() { - assert.equal(-1, [1, 2, 3].indexOf(5)); - assert.equal(-1, [1, 2, 3].indexOf(0)); - }); -}); \ No newline at end of file + afterEach(() => { + document = null; + }); + + it("receives error diagnostics from the server", () => { + const receivedDiagnostics = vscode.languages.getDiagnostics(docUri); + const normalizedReceivedDiagnostics = JSON.parse(JSON.stringify(receivedDiagnostics)); + expect(normalizedReceivedDiagnostics).to.eql([ + { + severity: "Error", + message: "\tExpected one of the following:\n Sql\n Json\n GraphQl", + range: [ + { + line: 0, + character: 13 + }, + { + line: 0, + character: 13 + } + ], + source: "FromClause" + } + ]); + }); + + it("receives hover help from the server", async () => { + const hoverHelp = (await vscode.commands.executeCommand( + "vscode.executeHoverProvider", + docUri, + new vscode.Position(0, 0) + )) as vscode.Hover; + const normalizedHoverHelp = JSON.parse(JSON.stringify(hoverHelp)); + expect(normalizedHoverHelp).to.eql([ + { + contents: [ + { + sanitize: true, + value: "```\nMappingDecl\n```" + } + ], + range: [ + { + line: 0, + character: 0 + }, + { + line: 0, + character: 7 + } + ] + } + ]); + }); +}); diff --git a/vscode-langserver-sms/src/test/index.ts b/vscode-langserver-sms/src/test/index.ts index 9fa2ea0..b018338 100644 --- a/vscode-langserver-sms/src/test/index.ts +++ b/vscode-langserver-sms/src/test/index.ts @@ -10,13 +10,14 @@ // to report the results back to the caller. When the tests are finished, return // a possible error to the callback or null if none. -import * as testRunner from 'vscode/lib/testrunner'; +import * as testRunner from "vscode/lib/testrunner"; // You can directly control Mocha options by uncommenting the following lines // See https://github.com/mochajs/mocha/wiki/Using-mocha-programmatically#set-options for more info testRunner.configure({ - ui: 'tdd', // the TDD UI is being used in extension.test.ts (suite, test, etc.) - useColors: true // colored output from test results + ui: "bdd", + useColors: true, // colored output from test results + timeout: 10000 // allow VSCode and server time to start }); -module.exports = testRunner; \ No newline at end of file +module.exports = testRunner; diff --git a/vscode-langserver-sms/yarn.lock b/vscode-langserver-sms/yarn.lock index 878c406..a8c591c 100644 --- a/vscode-langserver-sms/yarn.lock +++ b/vscode-langserver-sms/yarn.lock @@ -2,6 +2,11 @@ # yarn lockfile v1 +"@types/chai@^4.1.7": + version "4.1.7" + resolved "https://registry.npmjs.org/@types/chai/-/chai-4.1.7.tgz#1b8e33b61a8c09cbe1f85133071baa0dbf9fa71a" + integrity sha512-2Y8uPt0/jwjhQ6EiluT0XCri1Dbplr0ZxfFXUz+ye13gaqE8u5gL5ppao1JrUYr9cIip5S6MvQzBS7Kke7U9VA== + "@types/mocha@^2.2.42": version "2.2.48" resolved "https://registry.npmjs.org/@types/mocha/-/mocha-2.2.48.tgz#3523b126a0b049482e1c3c11877460f76622ffab" @@ -129,6 +134,11 @@ assert-plus@1.0.0, assert-plus@^1.0.0: resolved "https://registry.npmjs.org/assert-plus/-/assert-plus-1.0.0.tgz#f12e0f3c5d77b0b1cdd9146942e4e96c1e4dd525" integrity sha1-8S4PPF13sLHN2RRpQuTpbB5N1SU= +assertion-error@^1.1.0: + version "1.1.0" + resolved "https://registry.npmjs.org/assertion-error/-/assertion-error-1.1.0.tgz#e60b6b0e8f301bd97e5375215bda406c85118c0b" + integrity sha512-jgsaNduz+ndvGyFt3uSuWqvy4lCnIJiovtouQN5JZHOKCS2QuhEdbcQHFhVksz2N2U9hXJo8odG7ETyWlEeuDw== + asynckit@^0.4.0: version "0.4.0" resolved "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz#c79ed97f7f34cb8f2ba1bc9790bcc366474b4b79" @@ -210,6 +220,18 @@ caseless@~0.12.0: resolved "https://registry.npmjs.org/caseless/-/caseless-0.12.0.tgz#1b681c21ff84033c826543090689420d187151dc" integrity sha1-G2gcIf+EAzyCZUMJBolCDRhxUdw= +chai@^4.2.0: + version "4.2.0" + resolved "https://registry.npmjs.org/chai/-/chai-4.2.0.tgz#760aa72cf20e3795e84b12877ce0e83737aa29e5" + integrity sha512-XQU3bhBukrOsQCuwZndwGcCVQHyZi53fQ6Ys1Fym7E4olpIqqZZhhoFJoaKVvV17lWQoXYwgWN2nF5crA8J2jw== + dependencies: + assertion-error "^1.1.0" + check-error "^1.0.2" + deep-eql "^3.0.1" + get-func-name "^2.0.0" + pathval "^1.1.0" + type-detect "^4.0.5" + chalk@^1.1.3: version "1.1.3" resolved "http://registry.npmjs.org/chalk/-/chalk-1.1.3.tgz#a8115c55e4a702fe4d150abd3872822a7e09fc98" @@ -230,6 +252,11 @@ chalk@^2.3.0: escape-string-regexp "^1.0.5" supports-color "^5.3.0" +check-error@^1.0.2: + version "1.0.2" + resolved "https://registry.npmjs.org/check-error/-/check-error-1.0.2.tgz#574d312edd88bb5dd8912e9286dd6c0aed4aac82" + integrity sha1-V00xLt2Iu13YkS6Sht1sCu1KrII= + chevrotain@3.0.1: version "3.0.1" resolved "http://registry.npmjs.org/chevrotain/-/chevrotain-3.0.1.tgz#4259e8ea707273e88b8d70c9f1e3fe108d9c2446" @@ -346,6 +373,13 @@ deep-assign@^1.0.0: dependencies: is-obj "^1.0.0" +deep-eql@^3.0.1: + version "3.0.1" + resolved "https://registry.npmjs.org/deep-eql/-/deep-eql-3.0.1.tgz#dfc9404400ad1c8fe023e7da1df1c147c4b444df" + integrity sha512-+QeIQyN5ZuO+3Uk5DYh6/1eKO0m0YmJFGNmFHGACpf1ClL1nmlV/p4gNgbl2pJGxgXb4faqo6UE+M5ACEMyVcw== + dependencies: + type-detect "^4.0.0" + define-properties@^1.1.2: version "1.1.3" resolved "https://registry.npmjs.org/define-properties/-/define-properties-1.1.3.tgz#cf88da6cbee26fe6db7094f61d870cbd84cee9f1" @@ -533,6 +567,11 @@ function-bind@^1.1.1: resolved "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz#a56899d3ea3c9bab874bb9773b7c5ede92f4895d" integrity sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A== +get-func-name@^2.0.0: + version "2.0.0" + resolved "https://registry.npmjs.org/get-func-name/-/get-func-name-2.0.0.tgz#ead774abee72e20409433a066366023dd6887a41" + integrity sha1-6td0q+5y4gQJQzoGY2YCPdaIekE= + getpass@^0.1.1: version "0.1.7" resolved "https://registry.npmjs.org/getpass/-/getpass-0.1.7.tgz#5eff8e3e684d569ae4cb2b1282604e8ba62149fa" @@ -1039,6 +1078,11 @@ path-parse@^1.0.6: resolved "https://registry.npmjs.org/path-parse/-/path-parse-1.0.6.tgz#d62dbb5679405d72c4737ec58600e9ddcf06d24c" integrity sha512-GSmOT2EbHrINBf9SR7CDELwlJ8AENk3Qn7OikK4nFYAu3Ote2+JYNVvkpAEQm3/TLNEJFD/xZJjzyxg3KBWOzw== +pathval@^1.1.0: + version "1.1.0" + resolved "https://registry.npmjs.org/pathval/-/pathval-1.1.0.tgz#b942e6d4bde653005ef6b71361def8727d0645e0" + integrity sha1-uULm1L3mUwBe9rcTYd74cn0GReA= + pause-stream@0.0.11, pause-stream@^0.0.11: version "0.0.11" resolved "http://registry.npmjs.org/pause-stream/-/pause-stream-0.0.11.tgz#fe5a34b0cbce12b5aa6a2b403ee2e73b602f1445" @@ -1487,6 +1531,11 @@ tweetnacl@^0.14.3, tweetnacl@~0.14.0: resolved "https://registry.npmjs.org/tweetnacl/-/tweetnacl-0.14.5.tgz#5ae68177f192d4456269d108afa93ff8743f4f64" integrity sha1-WuaBd/GS1EViadEIr6k/+HQ/T2Q= +type-detect@^4.0.0, type-detect@^4.0.5: + version "4.0.8" + resolved "https://registry.npmjs.org/type-detect/-/type-detect-4.0.8.tgz#7646fb5f18871cfbb7749e69bd39a6388eb7450c" + integrity sha512-0fr/mIH1dlO+x7TlcMy+bIDqKPsw/70tVyeHW787goQjhmqaZe10uwLujubK9q9Lg6Fiho1KUKDYz0Z7k7g5/g== + typescript@^2.6.1: version "2.9.2" resolved "https://registry.npmjs.org/typescript/-/typescript-2.9.2.tgz#1cbf61d05d6b96269244eb6a3bce4bd914e0f00c" diff --git a/vscode-langserver-sparql/fixtures/bad/basic-bad-select.sparql b/vscode-langserver-sparql/fixtures/bad/basic-bad-select.sparql new file mode 100644 index 0000000..c969f02 --- /dev/null +++ b/vscode-langserver-sparql/fixtures/bad/basic-bad-select.sparql @@ -0,0 +1,5 @@ +PREFIX fakePrefix: + +select distinct ?s wher { + ?s < +} \ No newline at end of file diff --git a/vscode-langserver-sparql/out/test/extension.test.js b/vscode-langserver-sparql/out/test/extension.test.js index 2d35c9d..d27e236 100644 --- a/vscode-langserver-sparql/out/test/extension.test.js +++ b/vscode-langserver-sparql/out/test/extension.test.js @@ -1,21 +1,115 @@ "use strict"; -// -// Note: This example test is leveraging the Mocha test framework. -// Please refer to their documentation on https://mochajs.org/ for help. -// +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; Object.defineProperty(exports, "__esModule", { value: true }); -// The module 'assert' provides assertion methods from node -const assert = require("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'; -// Defines a Mocha test suite to group tests of similar kind together -suite("Extension Tests", function () { - // Defines a Mocha unit test - test("Something 1", function () { - assert.equal(-1, [1, 2, 3].indexOf(5)); - assert.equal(-1, [1, 2, 3].indexOf(0)); +const chai_1 = require("chai"); +const path = require("path"); +const vscode = require("vscode"); +const sleep = (ms) => new Promise(resolve => setTimeout(resolve, ms)); +describe("SPARQL Language Server Extension", () => { + let docUri; + let document; + beforeEach(() => __awaiter(this, void 0, void 0, function* () { + const ext = vscode.extensions.getExtension("stardog-union.vscode-langserver-sparql"); + yield ext.activate(); + docUri = vscode.Uri.file(path.join(__dirname, "..", "..", "fixtures", "bad", "basic-bad-select.sparql")); + document = yield vscode.workspace.openTextDocument(docUri); + yield vscode.window.showTextDocument(document); + yield sleep(2000); // let server start + })); + afterEach(() => { + document = null; + }); + it("receives error diagnostics from the server", () => { + const receivedDiagnostics = vscode.languages.getDiagnostics(docUri); + const normalizedReceivedDiagnostics = JSON.parse(JSON.stringify(receivedDiagnostics)); + chai_1.expect(normalizedReceivedDiagnostics).to.eql([ + { + severity: "Error", + message: "'{' expected.", + range: [ + { + line: 2, + character: 19 + }, + { + line: 2, + character: 23 + } + ], + source: "GroupGraphPattern" + }, + { + message: "\tExpected one of the following:\n '^'\n IRIREF e.g. \n PNAME_LN\n PNAME_NS\n 'a'\n '!'\n '('\n VAR1 e.g. ?foo\n VAR2 e.g. ?bar", + range: [ + { + character: 5, + line: 3 + }, + { + character: 6, + line: 3 + } + ], + severity: "Error", + source: "PropertyListPathNotEmpty" + } + ]); }); + it("receives hover help from the server", () => __awaiter(this, void 0, void 0, function* () { + const hoverHelp = (yield vscode.commands.executeCommand("vscode.executeHoverProvider", docUri, new vscode.Position(0, 0))); + const normalizedHoverHelp = JSON.parse(JSON.stringify(hoverHelp)); + chai_1.expect(normalizedHoverHelp).to.eql([ + { + contents: [ + { + sanitize: true, + value: "```\nPrefixDecl\n```" + } + ], + range: [ + { + line: 0, + character: 0 + }, + { + line: 0, + character: 52 + } + ] + } + ]); + })); + it("receives completion suggestions from the server", () => __awaiter(this, void 0, void 0, function* () { + const completions = (yield vscode.commands.executeCommand("vscode.executeCompletionItemProvider", docUri, new vscode.Position(3, 5))); + const normalizedCompletions = JSON.parse(JSON.stringify(completions)); + console.log(JSON.stringify(normalizedCompletions, null, 2)); + chai_1.expect(normalizedCompletions).to.eql([ + { + contents: [ + { + sanitize: true, + value: "```\nSelectClause\n```" + } + ], + range: [ + { + line: 0, + character: 0 + }, + { + line: 0, + character: 18 + } + ] + } + ]); + })); }); //# sourceMappingURL=extension.test.js.map \ No newline at end of file diff --git a/vscode-langserver-sparql/out/test/extension.test.js.map b/vscode-langserver-sparql/out/test/extension.test.js.map index b4c6ac5..e83e005 100644 --- a/vscode-langserver-sparql/out/test/extension.test.js.map +++ b/vscode-langserver-sparql/out/test/extension.test.js.map @@ -1 +1 @@ -{"version":3,"file":"extension.test.js","sourceRoot":"","sources":["../../src/test/extension.test.ts"],"names":[],"mappings":";AAAA,EAAE;AACF,kEAAkE;AAClE,wEAAwE;AACxE,EAAE;;AAEF,2DAA2D;AAC3D,iCAAiC;AAEjC,0DAA0D;AAC1D,8CAA8C;AAC9C,oCAAoC;AACpC,+CAA+C;AAE/C,qEAAqE;AACrE,KAAK,CAAC,iBAAiB,EAAE;IAErB,4BAA4B;IAC5B,IAAI,CAAC,aAAa,EAAE;QAChB,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;QACvC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;IAC3C,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"} \ No newline at end of file +{"version":3,"file":"extension.test.js","sourceRoot":"","sources":["../../src/test/extension.test.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,+BAA8B;AAC9B,6BAA6B;AAC7B,iCAAiC;AAEjC,MAAM,KAAK,GAAG,CAAC,EAAU,EAAE,EAAE,CAAC,IAAI,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,CAAC;AAE9E,QAAQ,CAAC,kCAAkC,EAAE,GAAG,EAAE;IAChD,IAAI,MAAkB,CAAC;IACvB,IAAI,QAAoC,CAAC;IAEzC,UAAU,CAAC,GAAS,EAAE;QACpB,MAAM,GAAG,GAAG,MAAM,CAAC,UAAU,CAAC,YAAY,CAAC,wCAAwC,CAAE,CAAC;QACtF,MAAM,GAAG,CAAC,QAAQ,EAAE,CAAC;QACrB,MAAM,GAAG,MAAM,CAAC,GAAG,CAAC,IAAI,CACtB,IAAI,CAAC,IAAI,CAAC,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AChC;iBACF;gBACD,KAAK,EAAE;oBACL;wBACE,IAAI,EAAE,CAAC;wBACP,SAAS,EAAE,CAAC;qBACb;oBACD;wBACE,IAAI,EAAE,CAAC;wBACP,SAAS,EAAE,EAAE;qBACd;iBACF;aACF;SACF,CAAC,CAAC;IACL,CAAC,CAAA,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"} \ No newline at end of file diff --git a/vscode-langserver-sparql/out/test/index.js b/vscode-langserver-sparql/out/test/index.js index 8cbe4a5..ed6ec92 100644 --- a/vscode-langserver-sparql/out/test/index.js +++ b/vscode-langserver-sparql/out/test/index.js @@ -15,8 +15,9 @@ const testRunner = require("vscode/lib/testrunner"); // You can directly control Mocha options by uncommenting the following lines // See https://github.com/mochajs/mocha/wiki/Using-mocha-programmatically#set-options for more info testRunner.configure({ - ui: 'tdd', - useColors: true // colored output from test results + ui: "bdd", + useColors: true, + timeout: 10000 // allow VSCode and server time to start }); module.exports = testRunner; //# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/vscode-langserver-sparql/out/test/index.js.map b/vscode-langserver-sparql/out/test/index.js.map index e288077..5a8d715 100644 --- a/vscode-langserver-sparql/out/test/index.js.map +++ b/vscode-langserver-sparql/out/test/index.js.map @@ -1 +1 @@ -{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/test/index.ts"],"names":[],"mappings":";AAAA,EAAE;AACF,mEAAmE;AACnE,EAAE;AACF,8EAA8E;AAC9E,oDAAoD;AACpD,EAAE;AACF,+EAA+E;AAC/E,kFAAkF;AAClF,iFAAiF;AACjF,gFAAgF;AAChF,oDAAoD;;AAEpD,oDAAoD;AAEpD,6EAA6E;AAC7E,mGAAmG;AACnG,UAAU,CAAC,SAAS,CAAC;IACjB,EAAE,EAAE,KAAK;IACT,SAAS,EAAE,IAAI,CAAC,mCAAmC;CACtD,CAAC,CAAC;AAEH,MAAM,CAAC,OAAO,GAAG,UAAU,CAAC"} \ No newline at end of file +{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/test/index.ts"],"names":[],"mappings":";AAAA,EAAE;AACF,mEAAmE;AACnE,EAAE;AACF,8EAA8E;AAC9E,oDAAoD;AACpD,EAAE;AACF,+EAA+E;AAC/E,kFAAkF;AAClF,iFAAiF;AACjF,gFAAgF;AAChF,oDAAoD;;AAEpD,oDAAoD;AAEpD,6EAA6E;AAC7E,mGAAmG;AACnG,UAAU,CAAC,SAAS,CAAC;IACnB,EAAE,EAAE,KAAK;IACT,SAAS,EAAE,IAAI;IACf,OAAO,EAAE,KAAK,CAAC,wCAAwC;CACxD,CAAC,CAAC;AAEH,MAAM,CAAC,OAAO,GAAG,UAAU,CAAC"} \ No newline at end of file diff --git a/vscode-langserver-sparql/package.json b/vscode-langserver-sparql/package.json index 1d79bbf..44a611e 100644 --- a/vscode-langserver-sparql/package.json +++ b/vscode-langserver-sparql/package.json @@ -36,11 +36,13 @@ "compile": "tsc -p ./", "watch": "tsc -watch -p ./", "postinstall": "node ./node_modules/vscode/bin/install", - "test": "yarn run compile && node ./node_modules/vscode/bin/test" + "test": "yarn run compile && sh ./scripts/e2e-tests.sh" }, "devDependencies": { + "@types/chai": "^4.1.7", "@types/mocha": "^2.2.42", "@types/node": "^8.10.25", + "chai": "^4.2.0", "tslint": "^5.8.0", "typescript": "^2.6.1" }, @@ -49,5 +51,7 @@ "vscode": "^1.1.26", "vscode-languageclient": "^5.2.1" }, - "extensionDependencies": ["stardog-union.stardog-rdf-grammars"] + "extensionDependencies": [ + "stardog-union.stardog-rdf-grammars" + ] } diff --git a/vscode-langserver-sparql/scripts/e2e-tests.sh b/vscode-langserver-sparql/scripts/e2e-tests.sh new file mode 100644 index 0000000..aaa0261 --- /dev/null +++ b/vscode-langserver-sparql/scripts/e2e-tests.sh @@ -0,0 +1,7 @@ +#!/usr/bin/env bash + +export CODE_TESTS_PATH="$(pwd)/out/test" +export CODE_TESTS_WORKSPACE="$(pwd)/fixtures" +export CODE_EXTENSIONS_PATH="$(pwd)/.." + +node "$(pwd)/node_modules/vscode/bin/test" diff --git a/vscode-langserver-sparql/src/test/extension.test.ts b/vscode-langserver-sparql/src/test/extension.test.ts index a7a297f..85d859c 100644 --- a/vscode-langserver-sparql/src/test/extension.test.ts +++ b/vscode-langserver-sparql/src/test/extension.test.ts @@ -1,22 +1,121 @@ -// -// Note: This example test is leveraging the Mocha test framework. -// Please refer to their documentation on https://mochajs.org/ for help. -// +import { expect } from "chai"; +import * as path from "path"; +import * as vscode from "vscode"; -// The module 'assert' provides assertion methods from node -import * as assert from 'assert'; +const sleep = (ms: number) => new Promise(resolve => setTimeout(resolve, ms)); -// 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'; +describe("SPARQL Language Server Extension", () => { + let docUri: vscode.Uri; + let document: vscode.TextDocument | null; -// Defines a Mocha test suite to group tests of similar kind together -suite("Extension Tests", function () { + beforeEach(async () => { + const ext = vscode.extensions.getExtension("stardog-union.vscode-langserver-sparql")!; + await ext.activate(); + docUri = vscode.Uri.file( + path.join(__dirname, "..", "..", "fixtures", "bad", "basic-bad-select.sparql") + ); + document = await vscode.workspace.openTextDocument(docUri); + await vscode.window.showTextDocument(document); + await sleep(2000); // let server start + }); - // Defines a Mocha unit test - test("Something 1", function() { - assert.equal(-1, [1, 2, 3].indexOf(5)); - assert.equal(-1, [1, 2, 3].indexOf(0)); + afterEach(() => { + document = null; + }); + + it("receives error diagnostics from the server", () => { + const receivedDiagnostics = vscode.languages.getDiagnostics(docUri); + const normalizedReceivedDiagnostics = JSON.parse(JSON.stringify(receivedDiagnostics)); + expect(normalizedReceivedDiagnostics).to.eql([ + { + severity: "Error", + message: "'{' expected.", + range: [ + { + line: 2, + character: 19 + }, + { + line: 2, + character: 23 + } + ], + source: "GroupGraphPattern" + }, + { + message: + "\tExpected one of the following:\n '^'\n IRIREF e.g. \n PNAME_LN\n PNAME_NS\n 'a'\n '!'\n '('\n VAR1 e.g. ?foo\n VAR2 e.g. ?bar", + range: [ + { + character: 5, + line: 3 + }, + { + character: 6, + line: 3 + } + ], + severity: "Error", + source: "PropertyListPathNotEmpty" + } + ]); + }); + + it("receives hover help from the server", async () => { + const hoverHelp = (await vscode.commands.executeCommand( + "vscode.executeHoverProvider", + docUri, + new vscode.Position(0, 0) + )) as vscode.Hover; + const normalizedHoverHelp = JSON.parse(JSON.stringify(hoverHelp)); + expect(normalizedHoverHelp).to.eql([ + { + contents: [ + { + sanitize: true, + value: "```\nPrefixDecl\n```" + } + ], + range: [ + { + line: 0, + character: 0 + }, + { + line: 0, + character: 52 + } + ] + } + ]); + }); + + // Note that this test and the one above also test error-tolerance, since + // the language assistance comes after a parse error. + it("receives completion suggestions from the server", async () => { + const completions = (await vscode.commands.executeCommand( + "vscode.executeCompletionItemProvider", + docUri, + new vscode.Position(3, 5) + )) as vscode.CompletionList; + const normalizedSuggestedCompletion = JSON.parse(JSON.stringify(completions.items[0])); + expect(normalizedSuggestedCompletion).to.eql({ + label: "", + kind: "EnumMember", + insertText: "", + textEdit: { + range: [ + { + line: 3, + character: 5 + }, + { + line: 3, + character: 6 + } + ], + newText: "" + } }); -}); \ No newline at end of file + }); +}); diff --git a/vscode-langserver-sparql/src/test/index.ts b/vscode-langserver-sparql/src/test/index.ts index 9fa2ea0..b018338 100644 --- a/vscode-langserver-sparql/src/test/index.ts +++ b/vscode-langserver-sparql/src/test/index.ts @@ -10,13 +10,14 @@ // to report the results back to the caller. When the tests are finished, return // a possible error to the callback or null if none. -import * as testRunner from 'vscode/lib/testrunner'; +import * as testRunner from "vscode/lib/testrunner"; // You can directly control Mocha options by uncommenting the following lines // See https://github.com/mochajs/mocha/wiki/Using-mocha-programmatically#set-options for more info testRunner.configure({ - ui: 'tdd', // the TDD UI is being used in extension.test.ts (suite, test, etc.) - useColors: true // colored output from test results + ui: "bdd", + useColors: true, // colored output from test results + timeout: 10000 // allow VSCode and server time to start }); -module.exports = testRunner; \ No newline at end of file +module.exports = testRunner; diff --git a/vscode-langserver-sparql/yarn.lock b/vscode-langserver-sparql/yarn.lock index d3ac3a5..79680cf 100644 --- a/vscode-langserver-sparql/yarn.lock +++ b/vscode-langserver-sparql/yarn.lock @@ -2,6 +2,11 @@ # yarn lockfile v1 +"@types/chai@^4.1.7": + version "4.1.7" + resolved "https://registry.npmjs.org/@types/chai/-/chai-4.1.7.tgz#1b8e33b61a8c09cbe1f85133071baa0dbf9fa71a" + integrity sha512-2Y8uPt0/jwjhQ6EiluT0XCri1Dbplr0ZxfFXUz+ye13gaqE8u5gL5ppao1JrUYr9cIip5S6MvQzBS7Kke7U9VA== + "@types/mocha@^2.2.42": version "2.2.48" resolved "https://registry.npmjs.org/@types/mocha/-/mocha-2.2.48.tgz#3523b126a0b049482e1c3c11877460f76622ffab" @@ -129,6 +134,11 @@ assert-plus@1.0.0, assert-plus@^1.0.0: resolved "https://registry.npmjs.org/assert-plus/-/assert-plus-1.0.0.tgz#f12e0f3c5d77b0b1cdd9146942e4e96c1e4dd525" integrity sha1-8S4PPF13sLHN2RRpQuTpbB5N1SU= +assertion-error@^1.1.0: + version "1.1.0" + resolved "https://registry.npmjs.org/assertion-error/-/assertion-error-1.1.0.tgz#e60b6b0e8f301bd97e5375215bda406c85118c0b" + integrity sha512-jgsaNduz+ndvGyFt3uSuWqvy4lCnIJiovtouQN5JZHOKCS2QuhEdbcQHFhVksz2N2U9hXJo8odG7ETyWlEeuDw== + asynckit@^0.4.0: version "0.4.0" resolved "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz#c79ed97f7f34cb8f2ba1bc9790bcc366474b4b79" @@ -210,6 +220,18 @@ caseless@~0.12.0: resolved "https://registry.npmjs.org/caseless/-/caseless-0.12.0.tgz#1b681c21ff84033c826543090689420d187151dc" integrity sha1-G2gcIf+EAzyCZUMJBolCDRhxUdw= +chai@^4.2.0: + version "4.2.0" + resolved "https://registry.npmjs.org/chai/-/chai-4.2.0.tgz#760aa72cf20e3795e84b12877ce0e83737aa29e5" + integrity sha512-XQU3bhBukrOsQCuwZndwGcCVQHyZi53fQ6Ys1Fym7E4olpIqqZZhhoFJoaKVvV17lWQoXYwgWN2nF5crA8J2jw== + dependencies: + assertion-error "^1.1.0" + check-error "^1.0.2" + deep-eql "^3.0.1" + get-func-name "^2.0.0" + pathval "^1.1.0" + type-detect "^4.0.5" + chalk@^1.1.3: version "1.1.3" resolved "http://registry.npmjs.org/chalk/-/chalk-1.1.3.tgz#a8115c55e4a702fe4d150abd3872822a7e09fc98" @@ -230,6 +252,11 @@ chalk@^2.3.0: escape-string-regexp "^1.0.5" supports-color "^5.3.0" +check-error@^1.0.2: + version "1.0.2" + resolved "https://registry.npmjs.org/check-error/-/check-error-1.0.2.tgz#574d312edd88bb5dd8912e9286dd6c0aed4aac82" + integrity sha1-V00xLt2Iu13YkS6Sht1sCu1KrII= + chevrotain@3.0.1: version "3.0.1" resolved "http://registry.npmjs.org/chevrotain/-/chevrotain-3.0.1.tgz#4259e8ea707273e88b8d70c9f1e3fe108d9c2446" @@ -346,6 +373,13 @@ deep-assign@^1.0.0: dependencies: is-obj "^1.0.0" +deep-eql@^3.0.1: + version "3.0.1" + resolved "https://registry.npmjs.org/deep-eql/-/deep-eql-3.0.1.tgz#dfc9404400ad1c8fe023e7da1df1c147c4b444df" + integrity sha512-+QeIQyN5ZuO+3Uk5DYh6/1eKO0m0YmJFGNmFHGACpf1ClL1nmlV/p4gNgbl2pJGxgXb4faqo6UE+M5ACEMyVcw== + dependencies: + type-detect "^4.0.0" + define-properties@^1.1.2: version "1.1.3" resolved "https://registry.npmjs.org/define-properties/-/define-properties-1.1.3.tgz#cf88da6cbee26fe6db7094f61d870cbd84cee9f1" @@ -533,6 +567,11 @@ function-bind@^1.1.1: resolved "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz#a56899d3ea3c9bab874bb9773b7c5ede92f4895d" integrity sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A== +get-func-name@^2.0.0: + version "2.0.0" + resolved "https://registry.npmjs.org/get-func-name/-/get-func-name-2.0.0.tgz#ead774abee72e20409433a066366023dd6887a41" + integrity sha1-6td0q+5y4gQJQzoGY2YCPdaIekE= + getpass@^0.1.1: version "0.1.7" resolved "https://registry.npmjs.org/getpass/-/getpass-0.1.7.tgz#5eff8e3e684d569ae4cb2b1282604e8ba62149fa" @@ -1039,6 +1078,11 @@ path-parse@^1.0.6: resolved "https://registry.npmjs.org/path-parse/-/path-parse-1.0.6.tgz#d62dbb5679405d72c4737ec58600e9ddcf06d24c" integrity sha512-GSmOT2EbHrINBf9SR7CDELwlJ8AENk3Qn7OikK4nFYAu3Ote2+JYNVvkpAEQm3/TLNEJFD/xZJjzyxg3KBWOzw== +pathval@^1.1.0: + version "1.1.0" + resolved "https://registry.npmjs.org/pathval/-/pathval-1.1.0.tgz#b942e6d4bde653005ef6b71361def8727d0645e0" + integrity sha1-uULm1L3mUwBe9rcTYd74cn0GReA= + pause-stream@0.0.11, pause-stream@^0.0.11: version "0.0.11" resolved "http://registry.npmjs.org/pause-stream/-/pause-stream-0.0.11.tgz#fe5a34b0cbce12b5aa6a2b403ee2e73b602f1445" @@ -1488,6 +1532,11 @@ tweetnacl@^0.14.3, tweetnacl@~0.14.0: resolved "https://registry.npmjs.org/tweetnacl/-/tweetnacl-0.14.5.tgz#5ae68177f192d4456269d108afa93ff8743f4f64" integrity sha1-WuaBd/GS1EViadEIr6k/+HQ/T2Q= +type-detect@^4.0.0, type-detect@^4.0.5: + version "4.0.8" + resolved "https://registry.npmjs.org/type-detect/-/type-detect-4.0.8.tgz#7646fb5f18871cfbb7749e69bd39a6388eb7450c" + integrity sha512-0fr/mIH1dlO+x7TlcMy+bIDqKPsw/70tVyeHW787goQjhmqaZe10uwLujubK9q9Lg6Fiho1KUKDYz0Z7k7g5/g== + typescript@^2.6.1: version "2.9.2" resolved "https://registry.npmjs.org/typescript/-/typescript-2.9.2.tgz#1cbf61d05d6b96269244eb6a3bce4bd914e0f00c" diff --git a/vscode-langserver-turtle/fixtures/bad/basic-bad-turtle.ttl b/vscode-langserver-turtle/fixtures/bad/basic-bad-turtle.ttl new file mode 100644 index 0000000..e6bc7b5 --- /dev/null +++ b/vscode-langserver-turtle/fixtures/bad/basic-bad-turtle.ttl @@ -0,0 +1 @@ +@prefix \ No newline at end of file diff --git a/vscode-langserver-turtle/out/test/extension.test.js b/vscode-langserver-turtle/out/test/extension.test.js index 2d35c9d..10435b6 100644 --- a/vscode-langserver-turtle/out/test/extension.test.js +++ b/vscode-langserver-turtle/out/test/extension.test.js @@ -1,21 +1,75 @@ "use strict"; -// -// Note: This example test is leveraging the Mocha test framework. -// Please refer to their documentation on https://mochajs.org/ for help. -// +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; Object.defineProperty(exports, "__esModule", { value: true }); -// The module 'assert' provides assertion methods from node -const assert = require("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'; -// Defines a Mocha test suite to group tests of similar kind together -suite("Extension Tests", function () { - // Defines a Mocha unit test - test("Something 1", function () { - assert.equal(-1, [1, 2, 3].indexOf(5)); - assert.equal(-1, [1, 2, 3].indexOf(0)); +const chai_1 = require("chai"); +const path = require("path"); +const vscode = require("vscode"); +const sleep = (ms) => new Promise(resolve => setTimeout(resolve, ms)); +describe("Turtle Language Server Extension", () => { + let docUri; + let document; + beforeEach(() => __awaiter(this, void 0, void 0, function* () { + const ext = vscode.extensions.getExtension("stardog-union.vscode-langserver-turtle"); + yield ext.activate(); + docUri = vscode.Uri.file(path.join(__dirname, "..", "..", "fixtures", "bad", "basic-bad-turtle.ttl")); + document = yield vscode.workspace.openTextDocument(docUri); + yield vscode.window.showTextDocument(document); + yield sleep(2000); // let server start + })); + afterEach(() => { + document = null; + }); + it("receives error diagnostics from the server", () => { + const receivedDiagnostics = vscode.languages.getDiagnostics(docUri); + const normalizedReceivedDiagnostics = JSON.parse(JSON.stringify(receivedDiagnostics)); + chai_1.expect(normalizedReceivedDiagnostics).to.eql([ + { + severity: "Error", + message: "PNAME_NS expected.", + range: [ + { + line: 0, + character: 7 + }, + { + line: 0, + character: 7 + } + ], + source: "prefixID" + } + ]); }); + it("receives hover help from the server", () => __awaiter(this, void 0, void 0, function* () { + const hoverHelp = (yield vscode.commands.executeCommand("vscode.executeHoverProvider", docUri, new vscode.Position(0, 0))); + const normalizedHoverHelp = JSON.parse(JSON.stringify(hoverHelp)); + chai_1.expect(normalizedHoverHelp).to.eql([ + { + contents: [ + { + sanitize: true, + value: "```\nprefixID\n```" + } + ], + range: [ + { + line: 0, + character: 0 + }, + { + line: 0, + character: 7 + } + ] + } + ]); + })); }); //# sourceMappingURL=extension.test.js.map \ No newline at end of file diff --git a/vscode-langserver-turtle/out/test/extension.test.js.map b/vscode-langserver-turtle/out/test/extension.test.js.map index b4c6ac5..94fd8b3 100644 --- a/vscode-langserver-turtle/out/test/extension.test.js.map +++ b/vscode-langserver-turtle/out/test/extension.test.js.map @@ -1 +1 @@ -{"version":3,"file":"extension.test.js","sourceRoot":"","sources":["../../src/test/extension.test.ts"],"names":[],"mappings":";AAAA,EAAE;AACF,kEAAkE;AAClE,wEAAwE;AACxE,EAAE;;AAEF,2DAA2D;AAC3D,iCAAiC;AAEjC,0DAA0D;AAC1D,8CAA8C;AAC9C,oCAAoC;AACpC,+CAA+C;AAE/C,qEAAqE;AACrE,KAAK,CAAC,iBAAiB,EAAE;IAErB,4BAA4B;IAC5B,IAAI,CAAC,aAAa,EAAE;QAChB,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE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AC;qBACb;iBACF;aACF;SACF,CAAC,CAAC;IACL,CAAC,CAAA,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"} \ No newline at end of file diff --git a/vscode-langserver-turtle/out/test/index.js b/vscode-langserver-turtle/out/test/index.js index 8cbe4a5..ed6ec92 100644 --- a/vscode-langserver-turtle/out/test/index.js +++ b/vscode-langserver-turtle/out/test/index.js @@ -15,8 +15,9 @@ const testRunner = require("vscode/lib/testrunner"); // You can directly control Mocha options by uncommenting the following lines // See https://github.com/mochajs/mocha/wiki/Using-mocha-programmatically#set-options for more info testRunner.configure({ - ui: 'tdd', - useColors: true // colored output from test results + ui: "bdd", + useColors: true, + timeout: 10000 // allow VSCode and server time to start }); module.exports = testRunner; //# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/vscode-langserver-turtle/out/test/index.js.map b/vscode-langserver-turtle/out/test/index.js.map index e288077..5a8d715 100644 --- a/vscode-langserver-turtle/out/test/index.js.map +++ b/vscode-langserver-turtle/out/test/index.js.map @@ -1 +1 @@ -{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/test/index.ts"],"names":[],"mappings":";AAAA,EAAE;AACF,mEAAmE;AACnE,EAAE;AACF,8EAA8E;AAC9E,oDAAoD;AACpD,EAAE;AACF,+EAA+E;AAC/E,kFAAkF;AAClF,iFAAiF;AACjF,gFAAgF;AAChF,oDAAoD;;AAEpD,oDAAoD;AAEpD,6EAA6E;AAC7E,mGAAmG;AACnG,UAAU,CAAC,SAAS,CAAC;IACjB,EAAE,EAAE,KAAK;IACT,SAAS,EAAE,IAAI,CAAC,mCAAmC;CACtD,CAAC,CAAC;AAEH,MAAM,CAAC,OAAO,GAAG,UAAU,CAAC"} \ No newline at end of file +{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/test/index.ts"],"names":[],"mappings":";AAAA,EAAE;AACF,mEAAmE;AACnE,EAAE;AACF,8EAA8E;AAC9E,oDAAoD;AACpD,EAAE;AACF,+EAA+E;AAC/E,kFAAkF;AAClF,iFAAiF;AACjF,gFAAgF;AAChF,oDAAoD;;AAEpD,oDAAoD;AAEpD,6EAA6E;AAC7E,mGAAmG;AACnG,UAAU,CAAC,SAAS,CAAC;IACnB,EAAE,EAAE,KAAK;IACT,SAAS,EAAE,IAAI;IACf,OAAO,EAAE,KAAK,CAAC,wCAAwC;CACxD,CAAC,CAAC;AAEH,MAAM,CAAC,OAAO,GAAG,UAAU,CAAC"} \ No newline at end of file diff --git a/vscode-langserver-turtle/package.json b/vscode-langserver-turtle/package.json index becbb2e..58e1924 100644 --- a/vscode-langserver-turtle/package.json +++ b/vscode-langserver-turtle/package.json @@ -37,11 +37,13 @@ "compile": "tsc -p ./", "watch": "tsc -watch -p ./", "postinstall": "node ./node_modules/vscode/bin/install", - "test": "yarn run compile && node ./node_modules/vscode/bin/test" + "test": "yarn run compile && sh ./scripts/e2e-tests.sh" }, "devDependencies": { + "@types/chai": "^4.1.7", "@types/mocha": "^2.2.42", "@types/node": "^8.10.25", + "chai": "^4.2.0", "tslint": "^5.8.0", "typescript": "^2.6.1" }, @@ -50,5 +52,7 @@ "vscode": "^1.1.26", "vscode-languageclient": "^5.2.1" }, - "extensionDependencies": ["stardog-union.stardog-rdf-grammars"] + "extensionDependencies": [ + "stardog-union.stardog-rdf-grammars" + ] } diff --git a/vscode-langserver-turtle/scripts/e2e-tests.sh b/vscode-langserver-turtle/scripts/e2e-tests.sh new file mode 100644 index 0000000..aaa0261 --- /dev/null +++ b/vscode-langserver-turtle/scripts/e2e-tests.sh @@ -0,0 +1,7 @@ +#!/usr/bin/env bash + +export CODE_TESTS_PATH="$(pwd)/out/test" +export CODE_TESTS_WORKSPACE="$(pwd)/fixtures" +export CODE_EXTENSIONS_PATH="$(pwd)/.." + +node "$(pwd)/node_modules/vscode/bin/test" diff --git a/vscode-langserver-turtle/src/test/extension.test.ts b/vscode-langserver-turtle/src/test/extension.test.ts index a7a297f..d1be5d9 100644 --- a/vscode-langserver-turtle/src/test/extension.test.ts +++ b/vscode-langserver-turtle/src/test/extension.test.ts @@ -1,22 +1,76 @@ -// -// Note: This example test is leveraging the Mocha test framework. -// Please refer to their documentation on https://mochajs.org/ for help. -// +import { expect } from "chai"; +import * as path from "path"; +import * as vscode from "vscode"; -// The module 'assert' provides assertion methods from node -import * as assert from 'assert'; +const sleep = (ms: number) => new Promise(resolve => setTimeout(resolve, ms)); -// 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'; +describe("Turtle Language Server Extension", () => { + let docUri: vscode.Uri; + let document: vscode.TextDocument | null; -// Defines a Mocha test suite to group tests of similar kind together -suite("Extension Tests", function () { + beforeEach(async () => { + const ext = vscode.extensions.getExtension("stardog-union.vscode-langserver-turtle")!; + await ext.activate(); + docUri = vscode.Uri.file( + path.join(__dirname, "..", "..", "fixtures", "bad", "basic-bad-turtle.ttl") + ); + document = await vscode.workspace.openTextDocument(docUri); + await vscode.window.showTextDocument(document); + await sleep(2000); // let server start + }); - // Defines a Mocha unit test - test("Something 1", function() { - assert.equal(-1, [1, 2, 3].indexOf(5)); - assert.equal(-1, [1, 2, 3].indexOf(0)); - }); -}); \ No newline at end of file + afterEach(() => { + document = null; + }); + + it("receives error diagnostics from the server", () => { + const receivedDiagnostics = vscode.languages.getDiagnostics(docUri); + const normalizedReceivedDiagnostics = JSON.parse(JSON.stringify(receivedDiagnostics)); + expect(normalizedReceivedDiagnostics).to.eql([ + { + severity: "Error", + message: "PNAME_NS expected.", + range: [ + { + line: 0, + character: 7 + }, + { + line: 0, + character: 7 + } + ], + source: "prefixID" + } + ]); + }); + + it("receives hover help from the server", async () => { + const hoverHelp = (await vscode.commands.executeCommand( + "vscode.executeHoverProvider", + docUri, + new vscode.Position(0, 0) + )) as vscode.Hover; + const normalizedHoverHelp = JSON.parse(JSON.stringify(hoverHelp)); + expect(normalizedHoverHelp).to.eql([ + { + contents: [ + { + sanitize: true, + value: "```\nprefixID\n```" + } + ], + range: [ + { + line: 0, + character: 0 + }, + { + line: 0, + character: 7 + } + ] + } + ]); + }); +}); diff --git a/vscode-langserver-turtle/src/test/index.ts b/vscode-langserver-turtle/src/test/index.ts index 9fa2ea0..b018338 100644 --- a/vscode-langserver-turtle/src/test/index.ts +++ b/vscode-langserver-turtle/src/test/index.ts @@ -10,13 +10,14 @@ // to report the results back to the caller. When the tests are finished, return // a possible error to the callback or null if none. -import * as testRunner from 'vscode/lib/testrunner'; +import * as testRunner from "vscode/lib/testrunner"; // You can directly control Mocha options by uncommenting the following lines // See https://github.com/mochajs/mocha/wiki/Using-mocha-programmatically#set-options for more info testRunner.configure({ - ui: 'tdd', // the TDD UI is being used in extension.test.ts (suite, test, etc.) - useColors: true // colored output from test results + ui: "bdd", + useColors: true, // colored output from test results + timeout: 10000 // allow VSCode and server time to start }); -module.exports = testRunner; \ No newline at end of file +module.exports = testRunner; diff --git a/vscode-langserver-turtle/yarn.lock b/vscode-langserver-turtle/yarn.lock index fb82583..1cd3309 100644 --- a/vscode-langserver-turtle/yarn.lock +++ b/vscode-langserver-turtle/yarn.lock @@ -2,6 +2,11 @@ # yarn lockfile v1 +"@types/chai@^4.1.7": + version "4.1.7" + resolved "https://registry.npmjs.org/@types/chai/-/chai-4.1.7.tgz#1b8e33b61a8c09cbe1f85133071baa0dbf9fa71a" + integrity sha512-2Y8uPt0/jwjhQ6EiluT0XCri1Dbplr0ZxfFXUz+ye13gaqE8u5gL5ppao1JrUYr9cIip5S6MvQzBS7Kke7U9VA== + "@types/mocha@^2.2.42": version "2.2.48" resolved "https://registry.npmjs.org/@types/mocha/-/mocha-2.2.48.tgz#3523b126a0b049482e1c3c11877460f76622ffab" @@ -129,6 +134,11 @@ assert-plus@1.0.0, assert-plus@^1.0.0: resolved "https://registry.npmjs.org/assert-plus/-/assert-plus-1.0.0.tgz#f12e0f3c5d77b0b1cdd9146942e4e96c1e4dd525" integrity sha1-8S4PPF13sLHN2RRpQuTpbB5N1SU= +assertion-error@^1.1.0: + version "1.1.0" + resolved "https://registry.npmjs.org/assertion-error/-/assertion-error-1.1.0.tgz#e60b6b0e8f301bd97e5375215bda406c85118c0b" + integrity sha512-jgsaNduz+ndvGyFt3uSuWqvy4lCnIJiovtouQN5JZHOKCS2QuhEdbcQHFhVksz2N2U9hXJo8odG7ETyWlEeuDw== + asynckit@^0.4.0: version "0.4.0" resolved "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz#c79ed97f7f34cb8f2ba1bc9790bcc366474b4b79" @@ -210,6 +220,18 @@ caseless@~0.12.0: resolved "https://registry.npmjs.org/caseless/-/caseless-0.12.0.tgz#1b681c21ff84033c826543090689420d187151dc" integrity sha1-G2gcIf+EAzyCZUMJBolCDRhxUdw= +chai@^4.2.0: + version "4.2.0" + resolved "https://registry.npmjs.org/chai/-/chai-4.2.0.tgz#760aa72cf20e3795e84b12877ce0e83737aa29e5" + integrity sha512-XQU3bhBukrOsQCuwZndwGcCVQHyZi53fQ6Ys1Fym7E4olpIqqZZhhoFJoaKVvV17lWQoXYwgWN2nF5crA8J2jw== + dependencies: + assertion-error "^1.1.0" + check-error "^1.0.2" + deep-eql "^3.0.1" + get-func-name "^2.0.0" + pathval "^1.1.0" + type-detect "^4.0.5" + chalk@^1.1.3: version "1.1.3" resolved "http://registry.npmjs.org/chalk/-/chalk-1.1.3.tgz#a8115c55e4a702fe4d150abd3872822a7e09fc98" @@ -230,6 +252,11 @@ chalk@^2.3.0: escape-string-regexp "^1.0.5" supports-color "^5.3.0" +check-error@^1.0.2: + version "1.0.2" + resolved "https://registry.npmjs.org/check-error/-/check-error-1.0.2.tgz#574d312edd88bb5dd8912e9286dd6c0aed4aac82" + integrity sha1-V00xLt2Iu13YkS6Sht1sCu1KrII= + chevrotain@3.0.1: version "3.0.1" resolved "http://registry.npmjs.org/chevrotain/-/chevrotain-3.0.1.tgz#4259e8ea707273e88b8d70c9f1e3fe108d9c2446" @@ -346,6 +373,13 @@ deep-assign@^1.0.0: dependencies: is-obj "^1.0.0" +deep-eql@^3.0.1: + version "3.0.1" + resolved "https://registry.npmjs.org/deep-eql/-/deep-eql-3.0.1.tgz#dfc9404400ad1c8fe023e7da1df1c147c4b444df" + integrity sha512-+QeIQyN5ZuO+3Uk5DYh6/1eKO0m0YmJFGNmFHGACpf1ClL1nmlV/p4gNgbl2pJGxgXb4faqo6UE+M5ACEMyVcw== + dependencies: + type-detect "^4.0.0" + define-properties@^1.1.2: version "1.1.3" resolved "https://registry.npmjs.org/define-properties/-/define-properties-1.1.3.tgz#cf88da6cbee26fe6db7094f61d870cbd84cee9f1" @@ -533,6 +567,11 @@ function-bind@^1.1.1: resolved "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz#a56899d3ea3c9bab874bb9773b7c5ede92f4895d" integrity sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A== +get-func-name@^2.0.0: + version "2.0.0" + resolved "https://registry.npmjs.org/get-func-name/-/get-func-name-2.0.0.tgz#ead774abee72e20409433a066366023dd6887a41" + integrity sha1-6td0q+5y4gQJQzoGY2YCPdaIekE= + getpass@^0.1.1: version "0.1.7" resolved "https://registry.npmjs.org/getpass/-/getpass-0.1.7.tgz#5eff8e3e684d569ae4cb2b1282604e8ba62149fa" @@ -1039,6 +1078,11 @@ path-parse@^1.0.6: resolved "https://registry.npmjs.org/path-parse/-/path-parse-1.0.6.tgz#d62dbb5679405d72c4737ec58600e9ddcf06d24c" integrity sha512-GSmOT2EbHrINBf9SR7CDELwlJ8AENk3Qn7OikK4nFYAu3Ote2+JYNVvkpAEQm3/TLNEJFD/xZJjzyxg3KBWOzw== +pathval@^1.1.0: + version "1.1.0" + resolved "https://registry.npmjs.org/pathval/-/pathval-1.1.0.tgz#b942e6d4bde653005ef6b71361def8727d0645e0" + integrity sha1-uULm1L3mUwBe9rcTYd74cn0GReA= + pause-stream@0.0.11, pause-stream@^0.0.11: version "0.0.11" resolved "http://registry.npmjs.org/pause-stream/-/pause-stream-0.0.11.tgz#fe5a34b0cbce12b5aa6a2b403ee2e73b602f1445" @@ -1487,6 +1531,11 @@ tweetnacl@^0.14.3, tweetnacl@~0.14.0: resolved "https://registry.npmjs.org/tweetnacl/-/tweetnacl-0.14.5.tgz#5ae68177f192d4456269d108afa93ff8743f4f64" integrity sha1-WuaBd/GS1EViadEIr6k/+HQ/T2Q= +type-detect@^4.0.0, type-detect@^4.0.5: + version "4.0.8" + resolved "https://registry.npmjs.org/type-detect/-/type-detect-4.0.8.tgz#7646fb5f18871cfbb7749e69bd39a6388eb7450c" + integrity sha512-0fr/mIH1dlO+x7TlcMy+bIDqKPsw/70tVyeHW787goQjhmqaZe10uwLujubK9q9Lg6Fiho1KUKDYz0Z7k7g5/g== + typescript@^2.6.1: version "2.9.2" resolved "https://registry.npmjs.org/typescript/-/typescript-2.9.2.tgz#1cbf61d05d6b96269244eb6a3bce4bd914e0f00c"