Code Monkey home page Code Monkey logo

floss's Introduction

Floss

Unit-testing for those hard to reach places.

Node.js CI npm version

Uses Electron to provide a Mocha unit-testing environment which can be run headlessly or to debugged with DevTools. This was largely inspired by the electron-mocha and mocha-electron projects but didn't quite have the debugging features needed to develop tests.

Installation

Install globally:

npm install -g floss electron

Install locally within a project:

npm install floss electron --save-dev

Debug Mode

Open tests in an Electron window where test can can be debugged with debugger and dev tools.

await floss({
    path: 'test/*.js',
    debug: true
});

Mocha Reporter

The reporter and reporterOptions are pass-through options for Mocha to specify a different reporter when running Floss in non-debug mode.

await floss({
    path: 'test/*.js',
    reporter: 'xunit',
    reporterOptions: {
    	filename: 'report.xml'
    }
});

Custom Options

Additional properties can be passed to the test code by adding more values to the run options.

await floss({
    path: 'test/*.js',
    customUrl: 'http://localhost:8080' // <- custom
});

The test code and use the global options property to have access to the run options.

console.log(options.customUrl); // logs: http://localhost:8080

Electron Arguments

Commandline arguments can be passed to Electron directly by using args. In the example below, you may wan to disable Electron's user-gesture policy if you are testing HTML video or audio playback.

await floss({
    path: 'test/index.js',
    args: ['--autoplay-policy=no-user-gesture-required']
});

Command Line Usage

Arguments

  • --path or -p (String) Path to the file to test
  • --debug or -d (Boolean) Enable to run in headful mode, default false.
  • --quiet or -q (Boolean) Prevent console[log/info/error/warn/dir] messages from appearing in stdout.
  • --electron or -e (String) Path to the electron to use.
  • --reporter or -R (String) Mocha reporter type, default spec.
  • --reporterOptions or -O (String) Mocha reporter options.
  • --require or -r (String) Module to require (e.g., ts-node/register).
  • -- [args] Additional arguments can be passed to Electron after --

Usage

Command Line usage when installed globally:

floss --path "test/*.js"

Or installed locally:

node node_modules/.bin/floss --path "test/*.js"

Alernatively, within the package.json's' scripts:

{
    "scripts": {
        "test": "floss --path \"test/*.js\""
    }
}

Debug Mode

Open tests in an Electron window where test can can be debugged with debugger and dev tools.

floss --path "test/*.js" --debug

Using TypeScript

Support can easily be added for writing tests in TypeScript using ts-node.

floss --path "test/*.ts" --require ts-node/register

Istanbul Code Coverage

Floss supports nyc. To use it, just use floss as you would mocha:

nyc floss --path "test/*.js"

Mocha Reporter

Can use the same reporter options as the API mentioned above. The reporterOptions are expressed as a querystring, for instance varname=foo&another=bar.

floss --path "test/*.js" \
    --reporter=xunit \
    --reporterOptions output=report.xml

Electron Arguments

Supports passing additional arguments to Electron after --.

floss --path "test/*.js" -- --autoplay-policy=no-user-gesture-required

Custom Electron Version

Some application may require a specific version of Electron. Floss uses Electron 10.0.0+, but you can specific the path to your own version. The custom version can be used either through the commandline argument --electron, by setting the Node environmental variable ELECTRON_PATH or by setting the run option electron.

floss --path "test/.js" \
	--electron /usr/local/bin/electron
ELECTRON_PATH=/usr/local/bin/electron floss --path "test/*.js"

GitHub Actions Integration

name: Node.js CI
on:
  push:
    branches: [ '**' ]
    tags: [ '**' ]
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v2
    - uses: actions/setup-node@v1
      with:
        node-version: '12'
    - run: npm install
    - uses: GabrielBB/[email protected]
      with:
        run: npm test

floss's People

Contributors

andrewstart avatar audionerd avatar bigtimebuddy avatar dependabot[bot] avatar golgobot avatar mbittarelli avatar mbittarelli-jibo avatar seflless avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

floss's Issues

Typescript example

This project is written in typescript, yet there is no example as to how to run floss (using NPM or otherwise) with ts-node as a require as with regular mocha mocha -r ts-node/register /path/to/code/**.*.ts.

mocha args

Hello! Can we somehow pass args (like --exit or --timeout) to Mocha?

electron 14 removes remote module

Electron 14 has breaking changes for floss. Electron docs here https://github.com/electron/electron/blob/v13.1.4/docs/api/remote.md

Electron 14 is also the first version that allows you to enable webgpu by doing:

const {app, BrowserWindow} = require('electron')
app.commandLine.appendSwitch('enable-unsafe-webgpu')

(being able to test webgpu is really the only reason why it matters to me)

As you may guess, I'd like to have webgpu enabled in floss if possible too! I'm willing to fix and send a pr for both , but would like some guidance on what'd be acceptable to you. Just a fyi, browsing random sites with enable-unsafe-webgpu is supposedly unsafe because cross origin can read gpu data, i seriously dont think that matters though, especially for local testing.

The easiest thing to get floss working with v14 would be to just change the remote import to "@electron/remote" , so like a 1 line change.

enabling webgpu is also just 1 line, but the decision may or may not require some discussion with others.

Uncaught Exception: TypeError: Cannot use 'in' operator to search for 'detach'

Steps:

  • Be on Electron v2.0.0-beta.8
  • floss -p test.js -d

Expect:

  • Should see window appear with Developer Tools open on the bottom

Actual

  • Get an error dialog

The bug:

mainWindow.webContents.openDevTools('bottom');

The fix:

mainWindow.webContents.openDevTools({ mode: 'bottom' });

The relevant WebContents docs

Maybe the openDevTools API changed slightly between Electron versions?

Will try to do a PR when I have more time to test a binary.

display issue on window

Hi !
Thank for this awesome repository ! =)

I have a display issue on window.

The reporter out this :

←[0m←[0m
←[0m  _forEachDeep :: tag:String => Object => Function => undefined←[0m
  ←[32m  ÔêÜ←[0m←[90m should call func in all children←[0m

←[0m  _mapDeep :: tag:String => Object => Function => Object←[0m
  ←[32m  ÔêÜ←[0m←[90m should call func in all children←[0m
  ←[32m  ÔêÜ←[0m←[90m should return an object with the same structure←[0m
  ←[32m  ÔêÜ←[0m←[90m should return an object with children name equal ok←[0m

←[0m  .createFrom :: Object => Container←[0m
  ←[32m  ÔêÜ←[0m←[90m should expose createFrom←[0m
  ←[31m  1) should return a Container←[0m


←[92m ←[0m←[32m 5 passing←[0m←[90m (59ms)←[0m
←[31m  1 failing←[0m

←[0m  1) .createFrom :: Object => Container should return a Container:
←[0m←[31m     TypeError: Cannot read property 'should' of undefined←[0m←[90m
      at Context.it (C:\Users\florian\Main\modules\pixi-createfrom\test\index.js:90:14)
      at callFn (C:\Users\florian\Main\modules\pixi-createfrom\node_modules\floss\node_modules\mocha\lib\runnable.js:326:21)

Do you know where this issue come from ?

Running floss in Docker returns null

We have a test suite that we call like this: ./node_modules/floss/bin/floss.js --path test/index.js
Running it locally on our dev machines outside Docker works like expected, it runs the test suite and returns correct exit code.

However, running it inside Docker fails and returns null.
Here's the log:

0 info it worked if it ends with ok
1 verbose cli [ '/usr/local/bin/node', '/usr/local/bin/npm', 'run', 'test' ]
2 info using [email protected]
3 info using [email protected]
4 verbose run-script [ 'pretest', 'test', 'posttest' ]
5 info lifecycle [email protected]~pretest: [email protected]
6 info lifecycle [email protected]~test: [email protected]
7 verbose lifecycle [email protected]~test: unsafe-perm in lifecycle true
8 verbose lifecycle [email protected]~test: PATH: /usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/frontend/node_modules/.bin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games
9 verbose lifecycle [email protected]~test: CWD: /frontend
10 silly lifecycle [email protected]~test: Args: [ '-c',
10 silly lifecycle   './node_modules/floss/bin/floss.js --path test/index.js' ]
11 silly lifecycle [email protected]~test: Returned: code: 1  signal: null
12 info lifecycle [email protected]~test: Failed to exec test script
13 verbose stack Error: [email protected] test: `./node_modules/floss/bin/floss.js --path test/index.js`
13 verbose stack Exit status 1
13 verbose stack     at EventEmitter.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/index.js:304:16)
13 verbose stack     at EventEmitter.emit (events.js:182:13)
13 verbose stack     at ChildProcess.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/lib/spawn.js:55:14)
13 verbose stack     at ChildProcess.emit (events.js:182:13)
13 verbose stack     at maybeClose (internal/child_process.js:961:16)
13 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:248:5)
14 verbose pkgid [email protected]
15 verbose cwd /frontend
16 verbose Linux 4.15.0-42-generic
17 verbose argv "/usr/local/bin/node" "/usr/local/bin/npm" "run" "test"
18 verbose node v10.4.1
19 verbose npm  v6.1.0
20 error code ELIFECYCLE
21 error errno 1
22 error [email protected] test: `./node_modules/floss/bin/floss.js --path test/index.js`
22 error Exit status 1
23 error Failed at the [email protected] test script.
23 error This is probably not a problem with npm. There is likely additional logging output above.
24 verbose exit [ 1, true ]

node_modules/floss/bin/floss.js exists on path in Docker and so does test/index.js.

Is there a special set-up for floss in Docker, or is that a bug in floss?

If you need more info to reproduce this issue, just let me know, I am floss and Docker newbie. :)

Supporting native ESM

Mocha as partial native support since 7.1.0, and seems to be full support since 8.0.0. Any chance of bumping mocha?

Effort to port to Jest?

Hello, you might remember me from such issues as pixijs/pixijs#7554

Just wanted to get a hot take about the effort it might require to port this to Jest testing / make this work to run Jest tests as well?

Thank you!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.