Coder Social home page Coder Social logo

isabella232 / inline-fixtures Goto Github PK

View Code? Open in Web Editor NEW

This project forked from googlecloudplatform/inline-fixtures

0.0 0.0 0.0 70 KB

Tests and fixtures, together at last ๐Ÿ’•

License: Apache License 2.0

JavaScript 5.61% TypeScript 94.39%

inline-fixtures's Introduction

Google Cloud Platform logo

inline-fixtures

NPM Version Build Status Known Vulnerabilities Code Style: Google

Sometimes tests need fixture directories. Observe:

const a = require(path.join('module-require', 'relative', 'dot.js'));
const b = require(path.join('module-require', 'relative', 'dot-slash.js'));
//...

At this point it is not clear what the fixture files themselves actually do, or how the rest of the test file relates to them. One must have both the fixtures and the test open together to actually understand the test.

It would be nice if the fixtures were inline, next to the test source code.

inline-fixtures dynamically creates a temporary directory and populates it with the fixture layout you provide, and then calls the passed in function. This has the additional benefit that fixture mutation cannot leak from one test to another.

Example:

import {withFixtures} from 'inline-fixtures';

describe('tests for fs.readFileSync', () => {
  it('should have a test cases', async () => {
    const FIXTURES = {
      'README.md': 'Hello Mars.',
      anotherDir: {
        'index.js': '42;',
      },
    };
    await withFixtures(FIXTURES, async (fixturesDir) => {
      // A temporary `fixturesDir` exists at this point with `README.md`
      // and `anotherDir`. The latter contains `index.js`.
      const readmePath = path.join(fixturesDir, 'README.md');
      const contents = fs.readFileSync(readmePath, 'utf8');
      assert.strictEqual(contents, FIXTURES['README.md']);
    });
  });
});

Supported Node.js Versions

Our client libraries follow the Node.js release schedule. Libraries are compatible with all current active and maintenance versions of Node.js.

License

Apache-2.0


Made with โค๏ธ by the Google Node.js team.

NOTE: This is not an official Google product.

inline-fixtures's People

Contributors

justinbeckwith avatar ofrobots avatar pliski avatar release-please[bot] avatar renovate-bot avatar

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.