Skip to content

Commit

Permalink
Configure CircleCI and Add Basic Tests (stardog-union#72)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
jmrog authored Jan 3, 2019
1 parent ab6aab5 commit 6ff89c8
Show file tree
Hide file tree
Showing 35 changed files with 731 additions and 149 deletions.
26 changes: 13 additions & 13 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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:
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mapping from
1 change: 1 addition & 0 deletions vscode-langserver-sms/fixtures/good/minimal-mapping.sms
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mapping from json {} to {} where {}
2 changes: 1 addition & 1 deletion vscode-langserver-sms/out/extension.js

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

2 changes: 1 addition & 1 deletion vscode-langserver-sms/out/extension.js.map

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

67 changes: 51 additions & 16 deletions vscode-langserver-sms/out/test/extension.test.js

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

2 changes: 1 addition & 1 deletion vscode-langserver-sms/out/test/extension.test.js.map

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

5 changes: 3 additions & 2 deletions vscode-langserver-sms/out/test/index.js

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

2 changes: 1 addition & 1 deletion vscode-langserver-sms/out/test/index.js.map

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

8 changes: 6 additions & 2 deletions vscode-langserver-sms/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand All @@ -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"
]
}
7 changes: 7 additions & 0 deletions vscode-langserver-sms/scripts/e2e-tests.sh
Original file line number Diff line number Diff line change
@@ -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"
4 changes: 1 addition & 3 deletions vscode-langserver-sms/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
90 changes: 72 additions & 18 deletions vscode-langserver-sms/src/test/extension.test.ts
Original file line number Diff line number Diff line change
@@ -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));
});
});
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
}
]
}
]);
});
});
9 changes: 5 additions & 4 deletions vscode-langserver-sms/src/test/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
module.exports = testRunner;
Loading

0 comments on commit 6ff89c8

Please sign in to comment.