Skip to content

Commit

Permalink
Add some tests for generate.js
Browse files Browse the repository at this point in the history
  • Loading branch information
simonvbrae committed Dec 20, 2024
1 parent dfbd305 commit 720cfba
Show file tree
Hide file tree
Showing 5 changed files with 2,452 additions and 1,182 deletions.
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@
"dev-prod": "comunica-compile-config config/config-default.json > .tmp-comunica-engine.js && ./bin/queries-to-json.js && webpack serve --config webpack.config.js --mode production",
"dev": "comunica-compile-config config/config-default.json > .tmp-comunica-engine.js && ./bin/queries-to-json.js && webpack serve --config webpack.config.js --mode development",
"build": "node ./bin/generate.js",
"version": "manual-git-changelog onversion"
"version": "manual-git-changelog onversion",
"test": "jest"
},
"dependencies": {
"@babel/core": "^7.16.0",
Expand All @@ -69,6 +70,7 @@
"@turf/centroid": "^6.5.0",
"babel-loader": "^8.2.3",
"file-loader": "^6.0.0",
"jest": "^29.7.0",
"json-loader": "^0.5.7",
"leaflet": "^1.7.1",
"minimist": "^1.2.5",
Expand Down
4 changes: 4 additions & 0 deletions test-queries/1.sparql
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
prefix ex: <http://example.org/>
SELECT ?a ?b WHERE {
?a ex:example ?b.
}
38 changes: 38 additions & 0 deletions tests/generate.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { existsSync, readFileSync } from 'fs';
import { execSync } from 'child_process';

describe('Build test: generate.js', () => {
beforeAll(() => {
});

describe('generate.js', () => {
describe('command line arguments', () => {
beforeEach(() => {
execSync('rm -rf testBuildOutput');
});

afterEach(() => {
execSync('rm -rf testBuildOutput');
});

it('should correctly handle option -d', async() => {
execSync('node bin/generate.js -d testBuildOutput', { encoding: 'utf-8' }); // the default is 'buffer'
expect(existsSync('testBuildOutput')).toEqual(true);
});

it('should correctly handle option -q', async() => {
execSync('node bin/generate.js -d testBuildOutput -q tests/test-queries', { encoding: 'utf-8' }); // the default is 'buffer'
let buildQueries = JSON.parse(readFileSync("./build/queries.json")).queries;
expect(buildQueries).toEqual(
[
{
"name":"1",
"datasources":[],
"queryFormat":"sparql",
"query":"prefix ex: <http://example.org/>\nSELECT ?a ?b WHERE {\n ?a ex:example ?b.\n}"
}
]);
});
});
});
});
4 changes: 4 additions & 0 deletions tests/test-queries/1.sparql
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
prefix ex: <http://example.org/>
SELECT ?a ?b WHERE {
?a ex:example ?b.
}
Loading

0 comments on commit 720cfba

Please sign in to comment.