Skip to content

Commit

Permalink
Merge pull request #762 from Turfjs/tap-testing
Browse files Browse the repository at this point in the history
Use tap as main testing suite
  • Loading branch information
DenisCarriere authored May 27, 2017
2 parents 9ca43a0 + 92f8e6f commit 0a6ddb8
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 38 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "4.0.0",
"description": "a node.js library for performing geospatial operations with geojson",
"scripts": {
"test": "npm run lint && lerna bootstrap && lerna run test && npm run types",
"test": "npm run lint && lerna bootstrap && tap packages/*/test.js && npm run types",
"lint": "eslint packages",
"types": "tsc",
"prepublish": "node ./scripts/generate-readmes"
Expand Down Expand Up @@ -53,6 +53,7 @@
"eslint": "^2.0.0",
"eslint-config-mourner": "^2.0.0",
"lerna": "2.0.0-beta.34",
"tap": "^10.3.2",
"typescript": "^2.2.1",
"uglify-js": "~2.4.16"
}
Expand Down
33 changes: 17 additions & 16 deletions packages/turf-along/test.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,30 @@
var test = require('tape');
var fs = require('fs');
var path = require('path');
var test = require('tape');
var {featureCollection} = require('@turf/helpers');
var along = require('./');
var featurecollection = require('@turf/helpers').featureCollection;

var line = JSON.parse(fs.readFileSync(__dirname + '/test/fixtures/dc-line.geojson'));
var line = JSON.parse(fs.readFileSync(path.join(__dirname, 'test', 'fixtures', 'dc-line.geojson')));

test('turf-along', function (t) {
var pt1 = along(line, 1, 'miles');
var pt2 = along(line.geometry, 1.2, 'miles');
var pt3 = along(line, 1.4, 'miles');
var pt4 = along(line.geometry, 1.6, 'miles');
var pt5 = along(line, 1.8, 'miles');
var pt6 = along(line.geometry, 2, 'miles');
var pt7 = along(line, 100, 'miles');
var pt8 = along(line.geometry, 0, 'miles');
var fc = featurecollection([pt1,pt2,pt3,pt4,pt5,pt6,pt7,pt8]);
var pt1 = along(line, 1, 'miles');
var pt2 = along(line.geometry, 1.2, 'miles');
var pt3 = along(line, 1.4, 'miles');
var pt4 = along(line.geometry, 1.6, 'miles');
var pt5 = along(line, 1.8, 'miles');
var pt6 = along(line.geometry, 2, 'miles');
var pt7 = along(line, 100, 'miles');
var pt8 = along(line.geometry, 0, 'miles');
var fc = featureCollection([pt1,pt2,pt3,pt4,pt5,pt6,pt7,pt8]);

fc.features.forEach(function (f) {
t.ok(f);
t.equal(f.type, 'Feature');
t.equal(f.geometry.type, 'Point');
t.ok(f);
t.equal(f.type, 'Feature');
t.equal(f.geometry.type, 'Point');
});
t.equal(fc.features.length, 8);
t.equal(fc.features[7].geometry.coordinates[0], pt8.geometry.coordinates[0]);
t.equal(fc.features[7].geometry.coordinates[1], pt8.geometry.coordinates[1]);

t.end();
t.end();
});
4 changes: 3 additions & 1 deletion packages/turf-idw/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@
"homepage": "https://github.com/Turfjs/turf",
"devDependencies": {
"benchmark": "^2.1.4",
"tape": "^4.6.3"
"load-json-file": "^2.0.0",
"tape": "^4.6.3",
"write-json-file": "^2.2.0"
},
"dependencies": {
"@turf/bbox": "^4.3.0",
Expand Down
46 changes: 27 additions & 19 deletions packages/turf-idw/test.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,33 @@
var test = require('tape');
var idw = require('./');
var fs = require('fs');
const fs = require('fs');
const path = require('path');
const test = require('tape');
const write = require('write-json-file');
const load = require('load-json-file');
const idw = require('./');

test('idw', function (t) {
var testPoints = JSON.parse(fs.readFileSync('./test/in/data.geojson'));
const directories = {
in: path.join(__dirname, 'test', 'in') + path.sep,
out: path.join(__dirname, 'test', 'out') + path.sep
};

var idw1 = idw(testPoints, 'value', 0.5, 1, 'kilometers');
var idw2 = idw(testPoints, 'value', 0.5, 0.5, 'kilometers');
var idw3 = idw(testPoints, 'value', 2, 1, 'miles');
var idw4 = idw(testPoints, 'WRONGDataField', 0.5, 1, 'miles');
test('idw', t => {
const testPoints = load.sync(directories.in + 'data.geojson');

t.ok(idw1.features.length);
t.ok(idw2.features.length);
t.ok(idw3.features.length);
t.error(idw4);
const idw1 = idw(testPoints, 'value', 0.5, 1, 'kilometers');
const idw2 = idw(testPoints, 'value', 0.5, 0.5, 'kilometers');
const idw3 = idw(testPoints, 'value', 2, 1, 'miles');
const idw4 = idw(testPoints, 'WRONGDataField', 0.5, 1, 'miles');

if (process.env.REGEN) {
fs.writeFileSync(__dirname + '/test/out/idw1.geojson', JSON.stringify(idw1, null, 2));
fs.writeFileSync(__dirname + '/test/out/idw2.geojson', JSON.stringify(idw2, null, 2));
fs.writeFileSync(__dirname + '/test/out/idw3.geojson', JSON.stringify(idw3, null, 2));
}
t.ok(idw1.features.length);
t.ok(idw2.features.length);
t.ok(idw3.features.length);
t.error(idw4);

t.end();
if (process.env.REGEN) {
write.sync(directories.out + 'idw1.geojson', idw1);
write.sync(directories.out + 'idw2.geojson', idw2);
write.sync(directories.out + 'idw3.geojson', idw3);
}

t.end();
});
1 change: 0 additions & 1 deletion packages/turf-intersect/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ const fixtures = fs.readdirSync(directories.in).map(filename => {

test('intersect', t => {
for (const {name, geojson, filename} of fixtures) {
console.log('processing', name);
const features = geojson.features;
const result = intersect(features[0], features[1]);

Expand Down

0 comments on commit 0a6ddb8

Please sign in to comment.