nikku / karma-browserify

A fast Browserify integration for Karma that handles large projects with ease
MIT License
321 stars 50 forks source link

fs.createWriteStream is not a function #149

Closed Cyrillius closed 8 years ago

Cyrillius commented 8 years ago

Hello!

I am writing a library to send some information to a PLC with an industrial protocol. I am using bunyan to debug nicely my code. Unfortunately, this library is using the fs library and when this line is executed:

 var fs = require('fs');

I get in fact an empty object:

 {}

I try to use as in your example the library brfs but it's still not working and I really don't know what to do.

Here is my karma.conf.js:

// karma config file - project - test AngularJs 
var istanbul = require('browserify-istanbul')

module.exports = function(config) {
    config.set({
        frameworks: ['browserify','jasmine'],
        plugins: [
            'karma-phantomjs-launcher',
            'karma-chrome-launcher',
            'karma-jasmine',
            'karma-coverage',
            'karma-browserify'
        ],
        files: [
            'adsProtocol.js',
            'adsNodeClient.js',
            'test/**/*.spec.js'
        ],
        // start these browsers
        browsers: ['Chrome'],
        reporters: ['progress', 'coverage'],
        preprocessors: {
            'node_modules/**/*.js': ['browserify'], 
            'adsNodeClient.js': ['browserify'],
            'adsProtocol.js': ['browserify'],
            'test/**/*.spec.js': ['browserify'],
        },
        coverageReporter: {
            type: 'html',
            dir: 'coverage'
        },
        logLevel: config.DEBUG_INFO,
        singleRun: false,
        browserify: {
            debug: true,
            transform: [
                'brfs',
                istanbul({
                    'ignore': [ 'test/**/*.spec.js']
                })

            ],
            extensions: ['.js']
        }
    });
};

Here is my package.json:

{
  "name": "ads-node-client",
  "version": "0.0.3",
  "description": "ADS TWINCAT client for Node.js",
  "main": "adsNodeClient.js",
  "directories": {
    "test": "test"
  },
  "dependencies": {
    "bunyan": "^1.5.1"
  },
  "devDependencies": {
    "brfs": "^1.4.1",
    "browserify": "^11.2.0",
    "browserify-istanbul": "^0.2.1",
    "browserify-shim": "^3.8.10",
    "jasmine-core": "^2.3.4",
    "karma": "^0.13.10",
    "karma-browserify": "^4.4.0",
    "karma-chrome-launcher": "^0.2.0",
    "karma-coverage": "^0.5.2",
    "karma-jasmine": "^0.3.6",
    "karma-phantomjs-launcher": "^0.2.1",
    "phantomjs": "^1.9.18"
  },
  "browserify-shim": {
    "external": "global:External"
  },
  "scripts": {
    "test": "node test/test.js | bunyan -o short"
  },
  "repository": {
    "type": "git",
    "url": "git+https://github.com/Cyrillius/adsNodeClient.git"
  },
  "keywords": [
    "ADS",
    "TWINCAT",
    "Beckhoff",
    "AMS",
    "PLC"
  ],
  "author": "Cyril Praz",
  "license": "MIT",
  "bugs": {
    "url": "https://github.com/Cyrillius/adsNodeClient/issues"
  },
  "homepage": "https://github.com/Cyrillius/adsNodeClient#readme"
}

Here is the stack trace of the error:

Chrome 45.0.2454 (Windows 8 0.0.0) Device client1 should expose the default attributes FAILED
        TypeError: fs.createWriteStream is not a function
            at Logger.addStream (C:/Users/CYRILL~1/AppData/Local/Temp/61fea9cca908ba322c87aefe7df1a9ff.browserify:3804:27 <- node_modules/bunyan/lib/bunyan.js:535:0)
            at C:/Users/CYRILL~1/AppData/Local/Temp/61fea9cca908ba322c87aefe7df1a9ff.browserify:3687:18 <- node_modules/bunyan/lib/bunyan.js:418:0
            at Array.forEach (native)
            at new Logger (C:/Users/CYRILL~1/AppData/Local/Temp/61fea9cca908ba322c87aefe7df1a9ff.browserify:3686:25 <- node_modules/bunyan/lib/bunyan.js:417:0)
            at Function.createLogger (C:/Users/CYRILL~1/AppData/Local/Temp/61fea9cca908ba322c87aefe7df1a9ff.browserify:4709:12 <- node_modules/bunyan/lib/bunyan.js:1440:0)
            at new Client (C:/Users/CYRILL~1/AppData/Local/Temp/61fea9cca908ba322c87aefe7df1a9ff.browserify:3253:3513 <- adsNodeClient.js:9:0)
            at Object.<anonymous> (C:/Users/CYRILL~1/AppData/Local/Temp/61fea9cca908ba322c87aefe7df1a9ff.browserify:4792:20 <- test/client.spec.js:9:0)
        TypeError: Cannot read property 'host' of undefined
            at Object.<anonymous> (C:/Users/CYRILL~1/AppData/Local/Temp/61fea9cca908ba322c87aefe7df1a9ff.browserify:4812:24 <- test/client.spec.js:29:0)
Chrome 45.0.2454 (Windows 8 0.0.0): Executed 1 of 1 (1 FAILED) ERROR (0.059 secs / 0.006 secs)
03 10 2015 02:44:34.304:DEBUG [coverage]: Writing coverage to D:/Documents/Github/adsNodeClient/coverage/Chrome 45.0.2454 (Windows 8 0.0.0)

Yes I am working on windows and yes I know it's not the best to dev but in industrial engineering not a lot of softwares is running under linux or mac.

bendrucker commented 8 years ago

You can't use the fs streaming APIs in the browser and definitely not the write ones

https://github.com/substack/brfs#methods

Cyrillius commented 8 years ago

I am so stupid. I used to use your library with angular.js and browserify in client side.