Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

test-fixture

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

test-fixture - npm Package Compare versions

Comparing version 0.1.1 to 1.0.0

25

index.js
'use strict';
module.exports = fixtures;
fixtures.Fixtures = Fixtures;

@@ -12,15 +13,16 @@ var node_path = require('path');

function fixtures () {
var root = node_path.resolve('test', 'fixtures');
var path = fixtures._resolve(root, arguments);
return new Fixtures(path);
return new Fixtures(arguments);
}
function Fixtures (path) {
this.path = path;
// @param {Arguments|Array} args
function Fixtures (args) {
this.root = this._root();
this.path = fixtures._resolve(this.root, args);
};
// @param {path...} arguments
Fixtures.prototype.resolve = function() {
return fixtures._resolve(this.path, arguments);
// Method for override
// @returns the root of
Fixtures.prototype._root = function() {
return node_path.resolve('test', 'fixtures');
};

@@ -30,4 +32,4 @@

// @param {path...} arguments
Fixtures.prototype.dest = function() {
return fixtures._resolve(this.dir, arguments);
Fixtures.prototype.resolve = function() {
return fixtures._resolve(this.path, arguments);
};

@@ -64,3 +66,3 @@

self.dir = dir;
self.path = dir;
callback(err, dir);

@@ -70,2 +72,1 @@ });

};
{
"name": "test-fixture",
"version": "0.1.1",
"version": "1.0.0",
"description": "Copy test-fixtures to temp dir and get resolved file paths.",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -28,14 +28,13 @@ # test-fixture [![NPM version](https://badge.fury.io/js/test-fixture.svg)](http://badge.fury.io/js/test-fixture) [![Build Status](https://travis-ci.org/kaelzhang/node-test-fixture.svg?branch=master)](https://travis-ci.org/kaelzhang/node-test-fixture) [![Dependency Status](https://gemnasium.com/kaelzhang/node-test-fixture.svg)](https://gemnasium.com/kaelzhang/node-test-fixture)

var fixtures = require('test-fixture');
var f = fixtures();
var f = fixtures(); // by default, it will use 'test/fixtures' dir.
// copy test fixtures to the temp dir
// copy 'test/fixtures' to the temp dir
f.copy(function(err, dir){
f.resolve('a.js'); // '/<repo>/test/fixtures/a.js'
f.dest('a.js'); // '/<temp>/a.js'
f.resolve('a.js'); // '/<temp>/a.js'
});
```
### fixtures(path...)
### fixtures([path...])
Arguments | Dir of test fixtures
`arguments` | `base`(dir of test fixtures)
--------- | --------------------

@@ -48,23 +47,61 @@ `undefined` | `test/fixtures`

### .copy(callback)
Actually, the `base` is `path.resolve('text/fixtures', path...)`
### .copy([to], callback)
- to `path=` the destination folder where the test fixtures will be copied to. If not specified, `fixtures` will create a temporary dir.
- callback `function(err, dir)`
- err `Error`
- dir `path` the temporary directory for testing
- dir `path` the destination directory for testing
Copy the test fixtures into a temporary directory.
### .resolve(path...)
### .resolve([path...])
Resolves the paths to get the path of the test fixtures
### .dest(path...)
After `.copy()`ed, it will resolve paths based on the destination dir.
Resolves the paths to get the path of the copied test fixtures
If not, it will use the base dir. But never use both of them simultaneously.
If `.copy()` is not ready, it will returns `null`
```
/path/to/<base>
|-- a.js
/path/to/<to>
|-- a.js
```
## Licence
#### Without copying
```js
var f = fixtures(base);
f.resolve('a.js'); // -> /path/to/<base>/a.js
```
#### Using `.copy()`
```js
var f = fixtures(base);
f.copy(to, function(err, dir){
if (err) {
return;
}
f.resolve('a.js'); // -> /path/to/<to>/a.js
});
```
## For Implementors
### fixtures.Fixtures(args)
- args `Arguments|Array` paths to join
### Override: ._root()
Returns `path` the base root. By default, it will returns 'test/fixtures', but you can override this method to specify it by your own.
## License
MIT
<!-- do not want to make nodeinit to complicated, you can edit this whenever you want. -->

@@ -7,2 +7,3 @@ 'use strict';

var fs = require('fs');
var util = require('util');

@@ -82,10 +83,3 @@ var root = node_path.join(__dirname, 'fixtures');

describe(".dest()", function(){
it("null", function(done){
var f = fixtures('a');
expect(f.dest('a')).to.equal(null);
expect(f.dest()).to.equal(null);
done()
});
describe(".resolve(), copied", function(){
it("a", function(done){

@@ -99,4 +93,4 @@ var f = fixtures('a');

var path = dir;
expect(f.dest('a')).to.equal(node_path.join(path, 'a'));
expect(f.dest()).to.equal(path);
expect(f.resolve('a')).to.equal(node_path.join(path, 'a'));
expect(f.resolve()).to.equal(path);
});

@@ -106,1 +100,24 @@ });

describe("inheritance", function(){
it("override ._root()", function(done){
var Fixtures = fixtures.Fixtures;
function My (args) {
Fixtures.call(this, args);
}
util.inherits(My, Fixtures);
My.prototype._root = function() {
return __dirname;
};
function my () {
return new My(arguments);
}
var m = my();
expect(m.resolve()).to.equal(__dirname);
expect(m.resolve('a')).to.equal(node_path.join(__dirname, 'a'));
done();
});
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc