Skip to content

Commit

Permalink
Restructure test data to remove custom copying
Browse files Browse the repository at this point in the history
  • Loading branch information
alxndrsn committed Nov 9, 2017
1 parent e04b4f6 commit f5caee9
Show file tree
Hide file tree
Showing 41 changed files with 49 additions and 85 deletions.
8 changes: 1 addition & 7 deletions package-lock.json

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

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"clean": "rm -rf ./build/",
"jshint": "jshint src/**/*.js bin/*.js test/*.js test/**/*.js",
"release": "git tag v$(jq -r .version package.json) && git push --tags && npm publish",
"test": "npm run jshint && npm run clean && mocha test/**/*.spec.js"
"test": "npm run jshint && npm run clean && mkdir -p build/test && cp -r test/data build/test/data && mocha test/**/*.spec.js"
},
"bin": {
"medic-conf": "bin/medic-conf.js",
Expand Down Expand Up @@ -43,7 +43,6 @@
"lodash": "^4.17.4",
"memdown": "^1.4.1",
"mocha": "^3.4.2",
"ncp": "^2.0.0",
"pouchdb": "^6.3.4"
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
34 changes: 9 additions & 25 deletions test/fn/convert-forms.utils.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
const assert = require('chai').assert;
const fs = require('../../src/lib/sync-fs');
const path = require('path');
const warn = require('../../src/lib/log').warn;


module.exports = {
Expand All @@ -13,39 +11,25 @@ module.exports = {

this.timeout(30000); // allow time for form conversion

const projectDir = `build/test/${testName}`;
const projectDir = `build/test/data/${testName}`;

// recursively copy forms and expected XML to temp directory, and create
// tests dynamically

const srcDir = `test/data/${testName}`;
const targetDir = `${projectDir}/forms/${type}`;

fs.mkdir(targetDir);
fs.recurseFiles(targetDir)
.filter(file => file.endsWith('.expected.xml'))
.forEach(expectedXml => {

fs.recurseFiles(srcDir)
.forEach(file => {
if(file.endsWith('.expected.xml')) {
const generatedXml = expectedXml.replace(/\.expected\.xml$/, '.xml');

const expectedXml = file;
const generatedXml = `${targetDir}/${path.basename(file, '.expected.xml')}.xml`;
it(`should generate ${generatedXml} as expected`, () => {

it(`should generate ${generatedXml} as expected`, () => {
assert.ok(fs.exists(generatedXml), `Missing generated XML file: ${generatedXml}`);
assert.equal(fs.read(generatedXml), fs.read(expectedXml), `Content of ${generatedXml} was not as expected.`);

assert.ok(fs.exists(generatedXml), `Missing generated XML file: ${generatedXml}`);
assert.equal(fs.read(generatedXml), fs.read(expectedXml), `Content of ${generatedXml} was not as expected.`);

});

} else if(file.endsWith('.xlsx') ||
file.endsWith('.properties.json') ||
path.basename(file) === 'place-types.json') {

const targetName = path.basename(file);
fs.copy(file, `${targetDir}/${targetName}`);
} else {
warn(`Ignoring unexpected file type: ${file}`);
}
});

});

Expand Down
59 changes: 26 additions & 33 deletions test/fn/csv-to-docs.spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const assert = require('chai').assert;
const fs = require('../../src/lib/sync-fs');
const ncp = require('ncp');

const csvToDocs = require('../../src/fn/csv-to-docs');

Expand All @@ -10,38 +9,32 @@ describe('csv-to-docs', function() {
this.timeout(30000); // allow time for slow things

// given
const srcDir = `test/data/csv-to-docs`;
const testDir = `build/test/csv-to-docs`;

ncp(srcDir, testDir, function(err) {
if(err) done(err);

// when
csvToDocs(testDir)
.then(() => {
const generatedDocsDir = `${testDir}/json_docs`;
const expectedDocsDir = `${testDir}/expected-json_docs`;

// then
assert.equal(countFilesInDir(generatedDocsDir),
countFilesInDir(expectedDocsDir ),
`Different number of files in ${generatedDocsDir} and ${expectedDocsDir}.`);

fs.recurseFiles(expectedDocsDir)
.map(file => fs.path.basename(file))
.forEach(file => {
const expected = fs.read(`${expectedDocsDir}/${file}`);
const generated = fs.read(`${generatedDocsDir}/${file}`);

// and
assert.equal(generated, expected);
});

done();
})
.catch(done);

});
const testDir = `build/test/data/csv-to-docs`;

// when
csvToDocs(testDir)
.then(() => {
const generatedDocsDir = `${testDir}/json_docs`;
const expectedDocsDir = `${testDir}/expected-json_docs`;

// then
assert.equal(countFilesInDir(generatedDocsDir),
countFilesInDir(expectedDocsDir ),
`Different number of files in ${generatedDocsDir} and ${expectedDocsDir}.`);

fs.recurseFiles(expectedDocsDir)
.map(file => fs.path.basename(file))
.forEach(file => {
const expected = fs.read(`${expectedDocsDir}/${file}`);
const generated = fs.read(`${generatedDocsDir}/${file}`);

// and
assert.equal(generated, expected);
});

done();
})
.catch(done);

});

Expand Down
30 changes: 12 additions & 18 deletions test/fn/upload-docs.spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const api = require('../api-stub');
const assert = require('chai').assert;
const ncp = require('ncp');
const uploadDocs = require('../../src/fn/upload-docs');

describe('upload-docs', function() {
Expand All @@ -9,29 +8,24 @@ describe('upload-docs', function() {

it('should upload docs to pouch', function(done) {

// given the test files are copied over
const srcDir = `test/data/upload-docs`;
const testDir = `build/test/upload-docs`;
// given
const testDir = `build/test/data/upload-docs`;

ncp(srcDir, testDir, err => {
if(err) done(err);
assertDbEmpty()

assertDbEmpty()
.then(() => /* when */ uploadDocs(testDir, api.couchUrl))

.then(() => /* when */ uploadDocs(testDir, api.couchUrl))
.then(() => api.db.allDocs())
.then(res =>

.then(() => api.db.allDocs())
.then(res =>
// then
assert.deepEqual(res.rows.map(doc => doc.id), [
'one', 'three', 'two'
]))

// then
assert.deepEqual(res.rows.map(doc => doc.id), [
'one', 'three', 'two'
]))
.then(done)
.catch(done);

.then(done)
.catch(done);

});

});

Expand Down

0 comments on commit f5caee9

Please sign in to comment.