Skip to content

Commit

Permalink
added testing of samples from core, legacy tests from core and a vune…
Browse files Browse the repository at this point in the history
…rability check, core now at 3.1.4
  • Loading branch information
MichalCz committed Jun 18, 2017
1 parent 52d874e commit 74d5303
Show file tree
Hide file tree
Showing 9 changed files with 233 additions and 171 deletions.
3 changes: 3 additions & 0 deletions .gitattributes
@@ -0,0 +1,3 @@
# Ignore all differences in line endings
* -crlf

1 change: 1 addition & 0 deletions README.md
Expand Up @@ -6,6 +6,7 @@
[![Develop Build Status](https://travis-ci.org/signicode/scramjet.svg?branch=develop)](https://travis-ci.org/signicode/scramjet)
[![Dependencies](https://david-dm.org/signicode/scramjet/status.svg)](https://david-dm.org/signicode/scramjet)
[![Dev Dependencies](https://david-dm.org/signicode/scramjet/dev-status.svg)](https://david-dm.org/signicode/scramjet?type=dev)
[![Known Vulnerabilities](https://snyk.io/test/github/signicode/scramjet/badge.svg)](https://snyk.io/test/github/signicode/scramjet)

## What is scramjet

Expand Down
37 changes: 37 additions & 0 deletions docs/plugins.md
Expand Up @@ -11,3 +11,40 @@ objects containing prototype extensions. One special extension is "constructor"
that will be called in the stream constructor.

A quick example can be the [scramjet-fini](https://www.npmjs.com/package/scramjet-fini) module on npm.

A sample plugin
-----------------

Here's how a minimal plugin looks like:

```javascript
module.exports = {
DataStream = {
constructor(options) {
if (options.someValue) {
this.someData = true;
}
},
addId(func, prefix) {
const fin = fini(prefix || defaultPrefix.next().value);
return this.pipe(new this.constructor({
parallelTransform: (chunk) => func(chunk, fin.next().value)
}));
}
}
};
```

All methods, getters/setters are copied upon scramjet stream prototype of the same name. The `constructor` method is
called at the end of the constructor.

If a scramjet stream of a specific name does not exist, it will be added as a new class.

Testing plugins
-----------------

You can test your plugins as you like but it would be wise to check if your plugin doesn't break any scramjet-core
features. In order to do that set `SCRAMJET_TEST_HOME` to your designated plugin location and include
`path.resolve(require.resolve("scramjet-core"), "../test/v1/*.js")` from this dependency to your plugin as nodeunit.

This is until we come up with a better solution.
18 changes: 15 additions & 3 deletions gulpfile.js
@@ -1,4 +1,5 @@
const gulp = require("gulp");
const env = require('gulp-env');
const path = require("path");
const gutil = require("gulp-util");
const rename = require("gulp-rename");
Expand All @@ -10,6 +11,7 @@ const cache = require('gulp-cached');
const remember = require('gulp-remember');

const {Transform} = require('stream');
const corepath = path.dirname(require.resolve("scramjet-core"));

gulp.task('lint', function() {
return gulp.src('./lib/*.js')
Expand All @@ -22,7 +24,13 @@ gulp.task('lint', function() {
});

gulp.task("test_legacy", function () {
return gulp.src(path.resolve(require.resolve("scramjet-core"), "../../test/v1/*.js"))

return gulp.src(path.resolve(corepath, "../test/v1/*.js"))
.pipe(env({
vars: {
SCRAMJET_TEST_HOME: __dirname
}
}))
.pipe(nodeunit_runner({reporter: "verbose"}))
;
});
Expand Down Expand Up @@ -68,8 +76,12 @@ gulp.task("readme", function() {
);
});

gulp.task("docs", ["readme"], function() {
const corepath = path.dirname(require.resolve("scramjet-core"));
gulp.task("copy_docs", function() {
return gulp.src(path.resolve(corepath, "../docs/*"))
.pipe(gulp.dest("docs/"));
});

gulp.task("docs", ["copy_docs", "readme"], function() {
const jsdoc2md = require('jsdoc-to-markdown');

return gulp.src(["lib/*.js"])
Expand Down
1 change: 1 addition & 0 deletions jsdoc2md/partial/main.hbs
Expand Up @@ -6,6 +6,7 @@
[![Develop Build Status](https://travis-ci.org/signicode/scramjet.svg?branch=develop)](https://travis-ci.org/signicode/scramjet)
[![Dependencies](https://david-dm.org/signicode/scramjet/status.svg)](https://david-dm.org/signicode/scramjet)
[![Dev Dependencies](https://david-dm.org/signicode/scramjet/dev-status.svg)](https://david-dm.org/signicode/scramjet?type=dev)
[![Known Vulnerabilities](https://snyk.io/test/github/signicode/scramjet/badge.svg)](https://snyk.io/test/github/signicode/scramjet)

## What is scramjet

Expand Down
6 changes: 3 additions & 3 deletions package-lock.json

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

10 changes: 5 additions & 5 deletions package.json
Expand Up @@ -43,12 +43,15 @@
"devDependencies": {
"freeport": "^1.0.5",
"fs-promise": "^2.0.0",
"fs-then-native": "^2.0.0",
"gulp": "^3.9.1",
"gulp-cached": "^1.1.1",
"gulp-concat": "^2.6.0",
"gulp-env": "^0.4.0",
"gulp-exec": "^2.1.3",
"gulp-jshint": "^2.0.4",
"gulp-nodeunit-runner": "^0.2.2",
"gulp-remember": "^0.3.1",
"gulp-rename": "^1.2.2",
"gulp-util": "^3.0.7",
"jsdoc-to-markdown": "^3.0.0",
Expand All @@ -58,12 +61,9 @@
"nodeunit": "^0.11.0",
"request": "^2.79.0",
"request-promise": "^4.1.1",
"through2": "^2.0.3",
"fs-then-native": "^2.0.0",
"gulp-cached": "^1.1.1",
"gulp-remember": "^0.3.1"
"through2": "^2.0.3"
},
"dependencies": {
"scramjet-core": "^3.1.0"
"scramjet-core": "^3.1.4"
}
}
90 changes: 45 additions & 45 deletions samples/data-stream-filter.js
@@ -1,45 +1,45 @@
#!/usr/bin/env node
// module: data-stream, method: filter

const DataStream = require('../').DataStream;

exports.stream = () => DataStream.fromArray([1,2,3,4,5,6,7,8,9,10])
.filter((num) => num % 2 === 0) // return true for even numbers
;

exports.test = {
normal: (test) => {

test.expect(2);

const returned = exports.stream();

returned
.once("data", (num) => {
test.equals(num, 2, "First item must be even");
})
.toArray()
.then(
(ret) => {
test.equals(ret.toString(), '2,4,6,8,10', "Odd items need to be filtered out");
test.done();
}
);
},
filterAll: (test) => {

test.expect(1);

DataStream.fromArray([1,2,3,4,5])
.filter(() => 0)
.map(() => test.ok(false, "No data should be outputted even on merged transforms"))
.on("data", () => test.ok(false, "No data should be emitted"))
.on("end", () => {
test.ok(true, "Stream should end");
test.done();
});

}
};

exports.log = console.log.bind(console);
#!/usr/bin/env node
// module: data-stream, method: filter

const DataStream = require('../').DataStream;

exports.stream = () => DataStream.fromArray([1,2,3,4,5,6,7,8,9,10])
.filter((num) => num % 2 === 0) // return true for even numbers
;

exports.test = {
normal: (test) => {

test.expect(2);

const returned = exports.stream();

returned
.once("data", (num) => {
test.equals(num, 2, "First item must be even");
})
.toArray()
.then(
(ret) => {
test.equals(ret.toString(), '2,4,6,8,10', "Odd items need to be filtered out");
test.done();
}
);
},
filterAll: (test) => {

test.expect(1);
debugger;
DataStream.fromArray([1,2,3,4,5])
.filter(() => 0)
.map(() => test.ok(false, "No data should be outputted even on merged transforms"))
.on("data", () => test.ok(false, "No data should be emitted"))
.on("end", () => {
test.ok(true, "Stream should end");
test.done();
});

}
};

exports.log = console.log.bind(console);

0 comments on commit 74d5303

Please sign in to comment.