-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #26 from xicombd/browser
Running the tests in the browser
- Loading branch information
Showing
7 changed files
with
298 additions
and
157 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
module.exports = function (config) { | ||
config.set({ | ||
|
||
// base path, that will be used to resolve files and exclude | ||
basePath: '', | ||
|
||
// frameworks to use | ||
frameworks: ['mocha'], | ||
|
||
// list of files / patterns to load in the browser | ||
files: [ | ||
'tests/browser-tests.js' | ||
], | ||
|
||
// list of preprocessors | ||
preprocessors: { | ||
'tests/*': ['webpack'] | ||
}, | ||
|
||
webpack: { | ||
resolve: { | ||
extensions: ['', '.js'] | ||
}, | ||
externals: { | ||
fs: '{}' | ||
}, | ||
node: { | ||
Buffer: true | ||
} | ||
}, | ||
|
||
webpackMiddleware: { | ||
noInfo: true, | ||
stats: { | ||
colors: true | ||
} | ||
}, | ||
|
||
// test results reporter to use | ||
// possible values: 'dots', 'progress', 'junit', 'growl', 'coverage' | ||
reporters: ['spec'], | ||
|
||
// web server port | ||
port: 9876, | ||
|
||
// enable / disable colors in the output (reporters and logs) | ||
colors: true, | ||
|
||
// level of logging | ||
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG | ||
logLevel: config.LOG_INFO, | ||
|
||
// enable / disable watching file and executing tests whenever any file changes | ||
autoWatch: false, | ||
|
||
// Start these browsers, currently available: | ||
// - Chrome | ||
// - ChromeCanary | ||
// - Firefox | ||
// - Opera (has to be installed with `npm install karma-opera-launcher`) | ||
// - Safari (only Mac; has to be installed with `npm install karma-safari-launcher`) | ||
// - PhantomJS | ||
// - IE (only Windows; has to be installed with `npm install karma-ie-launcher`) | ||
browsers: process.env.TRAVIS ? ['Firefox'] : ['Chrome'], | ||
|
||
// If browser does not capture in given timeout [ms], kill it | ||
captureTimeout: 60000, | ||
|
||
// Continuous Integration mode | ||
// if true, it capture browsers, run tests and exit | ||
singleRun: true | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* globals describe, before */ | ||
|
||
// const expect = require('chai').expect | ||
const async = require('async') | ||
const store = require('local-storage-blob-store') | ||
const tests = require('./repo-test') | ||
const _ = require('lodash') | ||
const IPFSRepo = require('../src') | ||
|
||
var repoContext = require.context('raw!./test-repo', true) | ||
|
||
describe('IPFS Repo Testson on the Browser', function () { | ||
before(function (done) { | ||
window.localStorage.clear() | ||
|
||
var repoData = [] | ||
repoContext.keys().forEach(function (key) { | ||
repoData.push({ | ||
key: key.replace('./', ''), | ||
value: repoContext(key) | ||
}) | ||
}) | ||
|
||
var mainBlob = store('ipfs') | ||
var blocksBlob = store('ipfs/') | ||
|
||
async.eachSeries(repoData, (file, cb) => { | ||
if (_.startsWith(file.key, 'datastore/')) { | ||
return cb() | ||
} | ||
|
||
const blob = _.startsWith(file.key, 'blocks/') | ||
? blocksBlob | ||
: mainBlob | ||
|
||
blob.createWriteStream({ | ||
key: file.key | ||
}).end(file.value, cb) | ||
}, done) | ||
}) | ||
|
||
const options = { | ||
stores: { | ||
keys: store, | ||
config: store, | ||
datastore: store, | ||
// datastoreLegacy: needs https://github.com/ipfs/js-ipfs-repo/issues/6#issuecomment-164650642 | ||
logs: store, | ||
locks: store, | ||
version: store | ||
} | ||
} | ||
const repo = new IPFSRepo('ipfs', options) | ||
tests(repo) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* globals describe, before, after */ | ||
|
||
const expect = require('chai').expect | ||
const ncp = require('ncp').ncp | ||
const rimraf = require('rimraf') | ||
|
||
const IPFSRepo = require('../src') | ||
|
||
describe('IPFS Repo Testson on Node.js', () => { | ||
const testRepoPath = __dirname + '/test-repo' | ||
const date = Date.now().toString() | ||
const repoPath = testRepoPath + date | ||
|
||
before(done => { | ||
ncp(testRepoPath, repoPath, err => { | ||
expect(err).to.not.exist | ||
done() | ||
}) | ||
}) | ||
|
||
after(done => { | ||
rimraf(repoPath, err => { | ||
expect(err).to.not.exist | ||
done() | ||
}) | ||
}) | ||
|
||
const fs = require('fs-blob-store') | ||
const options = { | ||
stores: { | ||
keys: fs, | ||
config: fs, | ||
datastore: fs, | ||
// datastoreLegacy: needs https://github.com/ipfs/js-ipfs-repo/issues/6#issuecomment-164650642 | ||
logs: fs, | ||
locks: fs, | ||
version: fs | ||
} | ||
} | ||
const repo = new IPFSRepo(repoPath, options) | ||
require('./repo-test')(repo) | ||
}) |
Oops, something went wrong.