Socket
Socket
Sign inDemoInstall

karma-fixture

Package Overview
Dependencies
0
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.2.4 to 0.2.5

26

lib/fixture.js

@@ -40,3 +40,3 @@ // Generated by CoffeeScript 1.9.2

Fixture.prototype.load = function() {
var append, err, filename, filenames, fixture_path, j, json, k, len, results, string;
var __html__, __json__, append, filename, filenames, fixture_path, ignore, j, json, k, len, results;
filenames = 2 <= arguments.length ? slice.call(arguments, 0, j = arguments.length - 1) : (j = 0, []), append = arguments[j++];

@@ -46,2 +46,4 @@ if (append == null) {

}
__html__ = window.__html__ || {};
__json__ = window.__json__ || {};
if (typeof append !== 'boolean') {

@@ -62,16 +64,20 @@ filenames.push(append);

}
string = typeof __html__ !== "undefined" && __html__ !== null ? __html__[fixture_path] : void 0;
if (string == null) {
this._throwNoFixture(fixture_path);
}
if (filename.indexOf('.json') !== -1) {
json = __json__[filename.replace('.json', '')] || __json__[filename] || __json__[fixture_path] || __json__[this.base + "/" + (filename.replace('.json', ''))];
if (json == null) {
this._throwNoFixture(fixture_path);
}
try {
json = JSON.parse(string);
this.json.push(json);
results.push(json);
json = JSON.parse(json);
} catch (_error) {
err = _error;
ignore = _error;
}
this.json.push(json);
results.push(json);
} else if (__html__[fixture_path]) {
results.push(this._appendFixture(__html__[fixture_path]));
} else {
results.push(this._appendFixture(string));
if (typeof string === "undefined" || string === null) {
this._throwNoFixture(fixture_path);
}
}

@@ -78,0 +84,0 @@ }

@@ -10,3 +10,3 @@ {

],
"version": "0.2.4",
"version": "0.2.5",
"author": "Bill Trikalinos <billtrik@gmail.com>",

@@ -30,3 +30,2 @@ "homepage": "https://github.com/billtrik/karma-fixture",

"grunt": "^0.4.5",
"grunt-bump": "0.3.1",
"grunt-cli": "^0.1.13",

@@ -33,0 +32,0 @@ "karma": "^0.12.31",

@@ -22,4 +22,4 @@ karma-fixture [![Build Status](https://travis-ci.org/billtrik/karma-fixture.svg?branch=master)](https://travis-ci.org/billtrik/karma-fixture) [![NPM version](https://badge.fury.io/js/karma-fixture.svg)](http://badge.fury.io/js/karma-fixture)

config.set({
// ...
frameworks: ['mocha', 'fixture'],
// ...

@@ -36,2 +36,3 @@ ```

config.set({
// ...
files: [

@@ -43,3 +44,2 @@ {

],
// ...

@@ -49,9 +49,10 @@ ],

Finally you have to add the html2js karma preprocessor:
Finally you have to add the `html2js` and `karma-json-fixtures-preprocessor` karma preprocessors:
```sh
$ npm install karma-html2js-preprocessor --save-dev
$ npm install karma-json-fixtures-preprocessor --save-dev
```
and then configure Karma to load all html and JSON fixture files:
, configure Karma to load all html and JSON fixture files via those preprocessors:

@@ -61,11 +62,23 @@ ```javascript

config.set({
// ...
preprocessors: {
'**/*.html' : ['html2js'],
'**/*.json' : ['html2js']
'**/*.json' : ['json_fixtures']
},
// ...
```
and then setup the `karma-json-fixtures-preprocessor` plugin:
```javascript
module.exports = function(config){
config.set({
// ...
jsonFixturesPreprocessor: {
variableName: '__json__'
},
// ...
```
*(optional)* If the plugin won't get loaded by karma, you might have to declare it inside the `plugins` array in your Karma configuration
*(optional)* If the plugins won't get loaded by karma, you might have to declare them inside the `plugins` array in your Karma configuration
*(and maybe load `karma-html2js-preprocessor` as well)*:

@@ -80,5 +93,5 @@

'karma-html2js-preprocessor'
'karma-json-fixtures-preprocessor'
// ...
],
// ...

@@ -90,6 +103,7 @@ ```

All fixture files are pre-loaded as strings and placed inside the Karma-created `window.__html__` array.
All html fixture files are pre-loaded as strings and placed inside the Karma-created `window.__html__` object and all json fixtures are loaded inside
`window.__json__`.
The fixture plugin is exposed in the `window.fixture` object on every test run.
It loads fixture files from that array and appends the created html inside the `window.fixture.el` element that gets created on start-up.
It loads fixture files from these objects and appends the created html inside the `window.fixture.el` element that gets created on start-up. It appends loaded JSONs inside the `fixture.json` array.

@@ -96,0 +110,0 @@

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc