Skip to content

Commit

Permalink
Add release implementation (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
natlibfi-arlehiko authored Jun 15, 2020
1 parent f3b8183 commit 476785f
Show file tree
Hide file tree
Showing 10 changed files with 78 additions and 12 deletions.
17 changes: 13 additions & 4 deletions .drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@ name: Default
trigger:
event:
- push
- tag

steps:

- name: audit
image: node:12
commands:
- npm audit --package-lock-only --audit-level=moderate
- npm audit --package-lock-only --production --audit-level=moderate

- name: install
image: node:12
Expand Down Expand Up @@ -41,13 +42,21 @@ steps:
image: quay.io/natlibfi/nodejsscan
commands:
- python /usr/src/app/cli.py -d dist


- name: npm
image: plugins/npm
settings:
registry: 'https://registry.npmjs.org/'
token:
from_secret: npm_token
when:
event: tag
---
kind: secret
name: npm_token
data: 7uFoHnowZyWM6w7MyOYuJsf228yTMxHOeJYOVQ==
data: EbWoRzH5ezRXvRcRTfCbCYO4mBd3yYHK+e85U1bOHCjyBgZH4amm5yj/Dh19JH6GPF66IfER46je+IPm61BGGQ==
---
kind: signature
hmac: 134627e5382329d03f74f4365c8ab74ab7dc52a754ab17d3025c81246bb9a333
hmac: dbcf85def75c8aac780da7a844e728063859782bc2a78900460ee01ce07af6aa

...
2 changes: 2 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
coverage
.nyc_output
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ generateTests({
### Options
- **callback**: A callback function passed to Mocha's `it`. Receives Fixura's function as arguments.
- **path**: An array of path components which make up a path to the test fixtures directory
- **recurse**: Whether to recurse into the subdirectories of **path**. If `false` the last directory of the path is used as the name of the Mocha's describe-call and it's direct subdirectories are used as unit test directories. Defaults to **true**
- **fixura**: Options that are passed to Fixura.
- **useMetadataFile**: If set to true, reads and parses a file named `metadata.json` in each unit test directory. The content must be a JSON object and it's properties as passed to the unit test callback function. If a property `description` is present, it is used as the test's description. Defaults to *false*.
- **mocha**: An object which maps the following properties to Mocha's corresponding callbacks: **after**, **before**, **afterEach**, **beforeEach**
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"url": "[email protected]:natlibfi/fixugen-js.git"
},
"license": "LGPL-3.0+",
"version": "1.0.0-alpha.1",
"version": "1.0.0",
"main": "./dist/index.js",
"engines": {
"node": ">=12"
Expand Down
15 changes: 12 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,24 @@ import {readdirSync, existsSync, readFileSync} from 'fs';
export default ({
callback,
path,
recurse = true,
fixura = {},
useMetadataFile = false,
mocha = {}
}) => {
const describeCallback = mocha.describe || /* istanbul ignore next: Needs to be overriden in tests */ describe;
const itCallback = mocha.it || /* istanbul ignore next: Needs to be overriden in tests */ it;

const rootDir = joinPath(...path);
readdirSync(rootDir).forEach(dir => {
if (recurse) {
const rootDir = joinPath(...path);
return readdirSync(rootDir).forEach(dir => setup(dir, rootDir));
}

const rootDir = joinPath(...path.slice(0, -1));
const [subDir] = path.slice(-1);
setup(subDir, rootDir);

function setup(dir, rootDir) {
describeCallback(dir, () => {
setupMochaCallbacks();

Expand Down Expand Up @@ -72,5 +81,5 @@ export default ({
afterEach(afterEachCallback);
}
});
});
}
};
48 changes: 44 additions & 4 deletions src/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ describe('index', () => {
let callbackCount = 0; // eslint-disable-line functional/no-let

generateTests({
path: [__dirname, '..', 'test-fixtures'],
path: [__dirname, '..', 'test-fixtures', '01'],
callback: args => {
try {
expect(callbackCount).to.equal(0);
Expand All @@ -59,7 +59,7 @@ describe('index', () => {
},
describe: (description, callback) => {
try {
expect(description).to.equal('index');
expect(description).to.equal('test');
return callback();
} catch (err) {
done(err);
Expand All @@ -74,7 +74,7 @@ describe('index', () => {

generateTests({
useMetadataFile: true,
path: [__dirname, '..', 'test-fixtures'],
path: [__dirname, '..', 'test-fixtures', '01'],
callback: args => {
try {
expect(callbackCount).to.equal(0);
Expand All @@ -100,7 +100,47 @@ describe('index', () => {
},
describe: (description, callback) => {
try {
expect(description).to.equal('index');
expect(description).to.equal('test');
return callback();
} catch (err) {
done(err);
}
}
}
});
});

it('Should not recurse', done => {
let callbackCount = 0; // eslint-disable-line functional/no-let

generateTests({
path: [__dirname, '..', 'test-fixtures', '02'],
recurse: false,
callback: args => {
try {
expect(callbackCount).to.equal(0);
expect(args).to.be.an('object');
expect(args).to.have.all.keys('getFixture', 'getFixtures');
expect(args.getFixture('test.txt')).to.equal('foo');

callbackCount++; // eslint-disable-line no-plusplus
done();
} catch (err) {
done(err);
}
},
mocha: {
it: (description, callback) => {
try {
expect(description).to.equal('01');
return callback();
} catch (err) {
done(err);
}
},
describe: (description, callback) => {
try {
expect(description).to.equal('02');
return callback();
} catch (err) {
done(err);
Expand Down
File renamed without changes.
File renamed without changes.
4 changes: 4 additions & 0 deletions test-fixtures/02/01/metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"description": "foo",
"foo": "bar"
}
1 change: 1 addition & 0 deletions test-fixtures/02/01/test.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
foo

0 comments on commit 476785f

Please sign in to comment.