Skip to content

Commit

Permalink
Refactor tests and examples.
Browse files Browse the repository at this point in the history
- Move files:
  - Examples to examples/.
  - Tests to tests/.
  - Test server to tests/.
  - Core unit tests to tests/unit/.
  - Legacy browser tests to tests/legacy/.
  - Benchmarks to tests/benchmarks/.
  - WebSockets related to tests/websockets/.
  - Issue related to tests/issues/.
  - Support files to root.
  - Test deps added to main package.json.
- Update paths everywhere.
- Built bundles:
  - Support building multiple configurations.
  - dist/forge.js: core forge.
  - dist/forge.all.js: core + extra utils + networking.
- Update lib/form.js, lib/xhr.js to CommonJS.
- Update READMEs.
- Update test server with appropriate files.
- Add primary test index.
- Update legacy index and files for new layout.
- Update tests to use single forge bundles.
- Remove test trailing whitespace.
- Turn off legacy test scrolling due to performance.
  • Loading branch information
davidlehn committed Dec 21, 2016
1 parent c0a19a3 commit 4c9a0b6
Show file tree
Hide file tree
Showing 85 changed files with 672 additions and 732 deletions.
4 changes: 1 addition & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ build
config.log
config.status
configure
coverage
dist
node_modules
nodejs/coverage
nodejs/ui/forge-tests.js
tests/forge
2 changes: 1 addition & 1 deletion nodejs/.istanbul.yml → .istanbul.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
instrumentation:
root: ..
root: .
3 changes: 1 addition & 2 deletions .jscsrc
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"excludeFiles": [
"./lib/jsbn.js",
"./nodejs/ui/forge-tests.js"
"./lib/jsbn.js"
],
"disallowKeywords": ["with"],
"disallowKeywordsOnNewLine": ["else", "catch"],
Expand Down
1 change: 0 additions & 1 deletion .jshintignore
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
nodejs/ui/forge-tests.js
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ node_js:
- "6"
- "node"
sudo: false
install: (cd nodejs && npm install)
install: npm install
script:
- (cd nodejs && npm test)
- (cd nodejs && npm run test-karma)
- npm test
- npm run test-karma
notifications:
email:
on_success: change
Expand Down
48 changes: 27 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,13 @@ dist/forge.js
dist/forge.min.js
```

A bundle that adds some utilities and networking support is also available:

```
dist/forge.all.js
dist/forge.all.min.js
```

Include the file via:

```html
Expand All @@ -90,48 +97,47 @@ or
The above bundles will synchronously create a global 'forge' object.

The build process uses [webpack][] and the [config][./webpack.config.js] file
or process can be modified to generate a file or files that only contain the
parts of forge you need.
can be modified to generate a file or files that only contain the parts of
forge you need.

[Browserify][] override support is also present in `package.json`.

Keep in mind that these bundles will not include any WebWorker
scripts (eg: prime.worker.js) or their dependencies, so these will
need to be accessible from the browser if any WebWorkers are used.
Keep in mind that these bundles will not include any WebWorker scripts (eg:
prime.worker.js) or their dependencies (jsbn.js), so these will need to be
accessible from the browser if any WebWorkers are used.

<a name="testing" />
### Node.js testing ###

Forge natively runs in a [Node.js][] environment:

cd nodejs
npm install
npm test

See the [testing README][./tests/README.md] for full details.

### Manual browser testing ###
### Automated Node.js testing ###

Testing in a browser uses [webpack][] to combine forge and all tests and then
loading the result in a browser. A simple web server is provided that will
output the URL to load.
Forge natively runs in a [Node.js][] environment:

cd nodejs
npm install
npm run build
npm start

npm test

### Automated browser testing with Karma ###

Automated testing is done via [Karma][]. By default it will run the tests in a
headless manner with PhantomJS. You can also specify one or more browsers to
use.

cd nodejs
npm install
npm run test-karma # defaults to PhantomJS
npm run test-karma -- --browsers Chrome,Firefox,PhantomJS

### Manual browser testing ###

Testing in a browser uses [webpack][] to combine forge and all tests and then
loading the result in a browser. A simple web server is provided that will
output the URL to load. Unit tests and older legacy tests are provided.

cd nodejs
npm install
npm run build
npm run test-build
npm run test-server

### Old build system that includes flash support ###

Expand Down
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"Digital Bazaar, Inc."
],
"license": "BSD",
"main": ["js/forge.js"],
"main": ["dist/forge.js"],
"dependencies": {},
"ignore": [
"node_modules",
Expand Down
2 changes: 1 addition & 1 deletion tests/nodejs-create-cert.js → examples/create-cert.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var forge = require('../js/forge');
var forge = require('..');

console.log('Generating 1024-bit key-pair...');
var keys = forge.pki.rsa.generateKeyPair(1024);
Expand Down
2 changes: 1 addition & 1 deletion tests/nodejs-create-csr.js → examples/create-csr.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var forge = require('../js/forge');
var forge = require('..');

console.log('Generating 1024-bit key-pair...');
var keys = forge.pki.rsa.generateKeyPair(1024);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var forge = require('../js/forge');
var forge = require('..');

try {
// generate a keypair
Expand Down
2 changes: 1 addition & 1 deletion tests/nodejs-imap.js → examples/imap.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var forge = require('../js/forge');
var forge = require('..');
var net = require('net');

var socket = new net.Socket();
Expand Down
2 changes: 1 addition & 1 deletion tests/nodejs-sign-p7.js → examples/sign-p7.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var forge = require('../js/forge');
var forge = require('..');

try {
// create PKCS#7 signed data
Expand Down
2 changes: 1 addition & 1 deletion tests/nodejs-tls.js → examples/tls.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var forge = require('../js/forge');
var forge = require('..');

// function to create certificate
var createCert = function(cn, data) {
Expand Down
8 changes: 3 additions & 5 deletions nodejs/karma.conf.js → karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ module.exports = function(config) {

// list of files / patterns to load in the browser
files: [
//'test/*.js'
'ui/test.js'
'tests/unit/index.js'
],

// list of files to exclude
Expand All @@ -23,9 +22,8 @@ module.exports = function(config) {
// preprocess matching files before serving them to the browser
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
preprocessors: {
//'test/*.js': ['browserify'],
//'ui/test.js': ['browserify'],
'ui/test.js': ['webpack']
//'tests/unit/index.js': ['browserify'],
'tests/unit/index.js': ['webpack']
},

browserify: {
Expand Down
18 changes: 5 additions & 13 deletions lib/form.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
*
* Copyright (c) 2011-2014 Digital Bazaar, Inc. All rights reserved.
*/
(function($) {
var forge = require('./forge');

/**
* The form namespace.
*/
var form = {};
/* Form API */
var form = module.exports = forge.form = forge.form || {};

(function($) {

/**
* Regex for parsing a single name property (handles array brackets).
Expand Down Expand Up @@ -146,12 +146,4 @@ form.serialize = function(input, sep, dict) {
return rval;
};

/**
* The forge namespace and form API.
*/
if(typeof forge === 'undefined') {
forge = {};
}
forge.form = form;

})(jQuery);
16 changes: 16 additions & 0 deletions lib/index.all.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/**
* Node.js module for Forge with extra utils and networking.
*
* @author Dave Longley
*
* Copyright 2011-2016 Digital Bazaar, Inc.
*/
module.exports = require('./forge');
// require core forge
require('./index');
// additional utils and networking support
require('./form');
require('./socket');
require('./tlssocket');
require('./http');
require('./xhr');
17 changes: 7 additions & 10 deletions lib/xhr.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@
*
* Copyright (c) 2010-2013 Digital Bazaar, Inc.
*/
var forge = require('./forge');
require('./socket');
require('./http');

/* XHR API */
var xhrApi = module.exports = forge.xhr = forge.xhr || {};

(function($) {

// logging category
Expand Down Expand Up @@ -80,16 +87,9 @@ var _clients = {};
// the default maximum number of concurrents connections per client
var _maxConnections = 10;

// local aliases
if(typeof forge === 'undefined') {
forge = {};
}
var net = forge.net;
var http = forge.http;

// define the xhr interface
var xhrApi = {};

/**
* Initializes flash XHR support.
*
Expand Down Expand Up @@ -733,7 +733,4 @@ xhrApi.create = function(options) {
return xhr;
};

// expose public api
forge.xhr = xhrApi;

})(jQuery);
27 changes: 0 additions & 27 deletions nodejs/README.md

This file was deleted.

38 changes: 0 additions & 38 deletions nodejs/package.json

This file was deleted.

43 changes: 0 additions & 43 deletions nodejs/server.js

This file was deleted.

Loading

0 comments on commit 4c9a0b6

Please sign in to comment.