Giter Club home page Giter Club logo

ember-cli-blueprint-test-helpers's Introduction

ember-cli-blueprint-test-helpers

npm version Build Status Build status

test helpers for ember-cli blueprints

Installation

ember install ember-cli-blueprint-test-helpers

It should be noted that ember-cli-blueprint-test-helpers currently only works for testing blueprints inside addon projects.

Usage

Running Tests

The blueprint tests can be run by:

node_modules/.bin/mocha node-tests --recursive

For convenience you should add the following to your package.json:

"scripts": {
  "nodetest": "mocha node-tests --recursive"
}

to be able to use npm run nodetest to run the tests.

Generating Tests

Generate a blueprint test scaffold using the blueprint-test generator:

ember generate blueprint-test my-blueprint

which will generate a test file at node-tests/blueprints/my-blueprint-test.js.

Example Usage

const { 
  setupTestHooks,
  emberNew,
  emberGenerateDestroy,
} = require('ember-cli-blueprint-test-helpers/helpers');

const {
  expect
} = require('ember-cli-blueprint-test-helpers/chai');

describe('Acceptance: ember generate and destroy my-blueprint', function() {
  // create and destroy temporary working directories
  setupTestHooks(this);

  it('my-blueprint foo', function() {
    const args = ['my-blueprint', 'foo'];

    // create a new Ember.js app in the working directory
    return emberNew()

      // then generate and destroy the `my-blueprint` blueprint called `foo`
      .then(() => emberGenerateDestroy(args, (file) => {

        // and run some assertions in between
        expect(file('path/to/file.js'))
          .to.contain('file contents to match')
          .to.contain('more file contents\n');
      }));

     // magically done for you: assert that the generated files are destroyed again
  });
});

or more explicitly:

const { 
  setupTestHooks,
  emberNew,
  emberGenerate,
  emberDestroy,
} = require('ember-cli-blueprint-test-helpers/helpers');

const {
  expect,
  file,
} = require('ember-cli-blueprint-test-helpers/chai');

describe('Acceptance: ember generate and destroy my-blueprint', function() {
  // create and destroy temporary working directories
  setupTestHooks(this);

  it('my-blueprint foo', function() {
    const args = ['my-blueprint', 'foo'];

    // create a new Ember.js app in the working directory
    return emberNew()

      // then generate the `my-blueprint` blueprint called `foo`
      .then(() => emberGenerate(args))

      // then assert that the files were generated correctly
      .then(() => expect(file('path/to/file.js'))
        .to.contain('file contents to match')
        .to.contain('more file contents\n'))

      // then destroy the `my-blueprint` blueprint called `foo`
      .then(() => emberDestroy(args))

      // then assert that the files were destroyed correctly
      .then(() => expect(file('path/to/file.js')).to.not.exist);
  });
});

API Reference

This project exports two major API endpoints for you to use:

  • require('ember-cli-blueprint-test-helpers/chai')

    This endpoint exports the Chai assertion library including the chai-as-promised and chai-files plugins

  • require('ember-cli-blueprint-test-helpers/helpers')

    This endpoint exports the functions mentioned in the following API reference


setupTestHooks(scope, options)

Prepare the test context for the blueprint tests.

Parameters:

  • {Object} scope the test context (i.e. this)
  • {Object} [options] optional parameters
  • {Number} [options.timeout=20000] the test timeout in milliseconds
  • {Object} [options.tmpenv] object containing info about the temporary directory for the test.
  • {String} [options.cliPath='ember-cli'] path to the ember-cli dependency
  • {Boolean} [options.disabledTasks=['addon-install', 'bower-install', 'npm-install']] override the mocked installs Defaults to lib/helpers/tmp-env.js

Returns: {Promise}


emberNew(options)

Create a new Ember.js app or addon in the current working directory.

Parameters:

  • {Object} [options] optional parameters
  • {String} [options.target='app'] the type of project to create (app, addon or in-repo-addon)

Returns: {Promise}


emberGenerate(args)

Run a blueprint generator.

Parameters:

  • {Array.<String>} args arguments to pass to ember generate (e.g. ['my-blueprint', 'foo'])

Returns: {Promise}


emberDestroy(args)

Run a blueprint destructor.

Parameters:

  • {Array.<String>} args arguments to pass to ember destroy (e.g. ['my-blueprint', 'foo'])

Returns: {Promise}


emberGenerateDestroy(args, assertionCallback)

Run a blueprint generator and the corresponding blueprint destructor while checking assertions in between.

Parameters:

  • {Array.<String>} args arguments to pass to ember generate (e.g. ['my-blueprint', 'foo'])
  • {Function} assertionCallback the callback function in which the assertions should happen

Returns: {Promise}


modifyPackages(packages)

Modify the dependencies in the package.json file of the test project.

Parameters:

  • {Array.<Object>} packages the list of packages that should be added, changed or removed

setupPodConfig(options)

Setup usePods in .ember-cli and/or podModulePrefix in environment.js.

Parameters:

  • {Object} [options] optional parameters
  • {Boolean} [options.usePods] add usePods in .ember-cli
  • {Boolean} [options.podModulePrefix] set npodModulePrefix to app/pods in config/environment.js

Used by

License

This project is licensed under the MIT License.

ember-cli-blueprint-test-helpers's People

Contributors

beatriz avatar christophercurrie avatar dcyriller avatar dependabot-preview[bot] avatar dependabot-support avatar dependabot[bot] avatar greenkeeper[bot] avatar greenkeeperio-bot avatar homeslicesolutions avatar jcope2013 avatar jeradg avatar kimroen avatar mixonic avatar nathanhammond avatar pangratz avatar rwjblue avatar simonihmig avatar stefanpenner avatar trabus avatar turbo87 avatar twokul 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

Watchers

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

ember-cli-blueprint-test-helpers's Issues

Test with prompts

I checked open and closed issues and I havent found anything about this. How do I pass a prompt in the middle of a running test?

screen shot 2016-06-23 at 6 16 11 pm

Action required: Greenkeeper could not be activated 🚨

🚨 You need to enable Continuous Integration on all branches of this repository. 🚨

To enable Greenkeeper, you need to make sure that a commit status is reported on all branches. This is required by Greenkeeper because it uses your CI build statuses to figure out when to notify you about breaking changes.

Since we didn’t receive a CI status on the greenkeeper/initial branch, it’s possible that you don’t have CI set up yet. We recommend using Travis CI, but Greenkeeper will work with every other CI service as well.

If you have already set up a CI for this repository, you might need to check how it’s configured. Make sure it is set to run on all new branches. If you don’t want it to run on absolutely every branch, you can whitelist branches starting with greenkeeper/.

Once you have installed and configured CI on this repository correctly, you’ll need to re-trigger Greenkeeper’s initial pull request. To do this, please delete the greenkeeper/initial branch in this repository, and then remove and re-add this repository to the Greenkeeper App’s white list on Github. You'll find this list on your repo or organization’s settings page, under Installed GitHub Apps.

AppVeyor build broken

The build is currently broken on AppVeyor due to a failing assertion:

expect(result.outputStream.join(' ')).to.contain('install package\u001b[39m mocha');

/cc @trabus

Random Issues

  • ember-cli should be in devDependencies (for both ember-cli-blueprint-test-helpers and ember-cli-internal-test-helpers) to prevent ending up with 2 or 3 nested ember-cli versions on npm 2.x.
  • A new blueprint for ember-cli-blueprint-test-helpers should be created that does the test infrastructure setup in https://github.com/ember-cli/ember-cli-blueprint-test-helpers/blob/master/blueprints/blueprint-test/index.js#L16-L2. This would allow for ember install ember-cli-blueprint-test-helpers to do that work once at install time. Currently, this is done for every new blueprint generated.
  • Last tagged & released version includes incorrect version numbers in blueprint, causing blueprint to fail.
  • -nodetest.js file is generated in blueprints/ directory, but I would expect it in tests/blueprints/*-nodetest.js...
  • extra leading whitespace after setupTestHooks line in generated file
  • setupTestHooks line contains two semicolons (;;)

More random issues

  • symlink cleanup after tests are done
  • blueprint-test blueprint is currently installing addon-import blueprint when it shouldn't be
  • extract package.json fixtures to separate blueprint so they can be conditionally/optionally installed

.npmignore in blueprint replaces projects .npmignore

% ember install ember-cli-blueprint-test-helpers
version: 1.13.12
Installed packages for tooling via npm.
installing ember-cli-blueprint-test-helpers
[?] Overwrite .npmignore? Diff
Index: /Users/rjackson/Source/javascript/ember-data/.npmignore
===================================================================
--- /Users/rjackson/Source/javascript/ember-data/.npmignore
+++ /Users/rjackson/Source/javascript/ember-data/.npmignore
@@ -1,15 +1,1 @@
-bower_components/
-tests/
-tmp/
-dist/
-
-.bowerrc
-.editorconfig
-.ember-cli
-.travis.yml
-.npmignore
-**/.gitkeep
-bower.json
-Brocfile.js
-testem.json
-*.gem
+blueprint-nodetest.js
\ No newline at end of file

[?] Overwrite .npmignore? (Yndeh)

An in-range update of fs-extra is breaking the build 🚨

Version 2.1.2 of fs-extra just got published.

Branch Build failing 🚨
Dependency fs-extra
Current Version 2.1.1
Type dependency

This version is covered by your current version range and after updating it in your project the build failed.

As fs-extra is a direct dependency of this project this is very likely breaking your project right now. If other packages depend on you it’s very likely also breaking them.
I recommend you give this issue a very high priority. I’m sure you can resolve this 💪


Status Details
  • continuous-integration/travis-ci/push The Travis CI build failed Details

  • continuous-integration/appveyor/branch AppVeyor build succeeded Details

Commits

The new version differs by 4 commits .

  • 84717b8 2.1.2
  • fcb436d Update CHANGELOG
  • 6f2b6d1 Merge pull request #393 from jprichardson/rimraf-callback
  • 55c5eb0 Prevent callback from being called twice

See the full diff.

Not sure how things should work exactly?

There is a collection of frequently asked questions and of course you may always ask my humans.


Your Greenkeeper Bot 🌴

Allow opting out of the destroy phase for `emberGenerateDestroy`.

Due to ember-cli/ember-cli#5884, I cannot test destroying my addon's default blueprint. I have had to resort to the following (instead of using emberGenerateDestroy):

var emberGenerateDestroy = blueprintHelpers.emberGenerateDestroy;
var chai = require('ember-cli-blueprint-test-helpers/chai');
var expect = chai.expect;
var file = chai.file;

  it('ember-cli-template-lint without localization framework', function() {
    var args = ['ember-cli-template-lint'];

    return emberNew()
      .then(function() {
        return emberGenerate(args)
      })
      .then(function() {
          expect(file('.template-lintrc.js')).to.contain('extends: \'recommended\'');
      });
  });

Obviously, we should ensure the upstream issue is fixed and this becomes less of an issue, but should we allow an option to opt out of the destroy phase for now?

Remove "walk-sync" dependency

The walk-sync sync dependency is only used for debug output but is currently called unconditionally. We should either remove the debug output call and the dependency completely or make sure it is only executed when needed.

jest

thoughts on making this run off jest instead of mocha?

An in-range update of ember-cli is breaking the build 🚨

Version 2.16.0 of ember-cli was just published.

Branch Build failing 🚨
Dependency ember-cli
Current Version 2.15.1
Type devDependency

This version is covered by your current version range and after updating it in your project the build failed.

ember-cli is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • continuous-integration/appveyor/branch Waiting for AppVeyor build to complete Details
  • continuous-integration/travis-ci/push The Travis CI build failed Details

Release Notes Module Aerobics

Setup

npm install -g [email protected] -- Install new global ember-cli

Project Update

  1. rm -rf node_modules dist tmp -- Delete temporary development folders.
  2. npm install --save-dev [email protected] -- Update project's package.json to use latest version.
  3. npm install -- Reinstall NPM dependencies.
  4. ember init -- This runs the new project blueprint on your projects directory. Please follow the prompts, and review all changes (tip: you can see a diff by pressing d). The most common source of upgrade pain is missing changes in this step.

Changelog

The following changes are required if you are upgrading from the previous
version:

  • Users
  • Addon Developers
  • Core Contributors
    • No changes required

Community Contributions

Thank you to all who took the time to contribute!

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Version 10 of node.js has been released

Version 10 of Node.js (code name Dubnium) has been released! 🎊

To see what happens to your code in Node.js 10, Greenkeeper has created a branch with the following changes:

  • Added the new Node.js version to your .travis.yml

If you’re interested in upgrading this repo to Node.js 10, you can open a PR with these changes. Please note that this issue is just intended as a friendly reminder and the PR as a possible starting point for getting your code running on Node.js 10.

More information on this issue

Greenkeeper has checked the engines key in any package.json file, the .nvmrc file, and the .travis.yml file, if present.

  • engines was only updated if it defined a single version, not a range.
  • .nvmrc was updated to Node.js 10
  • .travis.yml was only changed if there was a root-level node_js that didn’t already include Node.js 10, such as node or lts/*. In this case, the new version was appended to the list. We didn’t touch job or matrix configurations because these tend to be quite specific and complex, and it’s difficult to infer what the intentions were.

For many simpler .travis.yml configurations, this PR should suffice as-is, but depending on what you’re doing it may require additional work or may not be applicable at all. We’re also aware that you may have good reasons to not update to Node.js 10, which is why this was sent as an issue and not a pull request. Feel free to delete it without comment, I’m a humble robot and won’t feel rejected 🤖


FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

This only works in addon projects

Due to the nature of how the emberApp helper sets up a test, and how blueprints are discovered, it's not currently possible to use blueprint test helpers inside a regular ember-cli app (the blueprint isn't able to be discovered in the temp project).

We should determine if adding support is desired or necessary, or if simply stating that it only works inside addons is okay.

Asserting contents of `app/router.js`

In the current state all asserted files are expected to be removed after the destroy command, but that makes it hard to assert the contents of app/router.js. We should probably introduce a notDestroyed flag or something like that.

Move blueprint-test to node-tests folder

To go with a more consistent structure for the tests, we should move the generated blueprint-nodetest.js in the blueprint-test blueprint to the node-tests folder.

  • create node-tests folder in blueprint-test blueprint files
  • change naming scheme from blueprint-nodetest.js to [blueprintname]-test.js
  • change .npmignore to ignore node-tests folder
  • change test runner to look into node-tests folder instead of looking for -nodetest
  • move blueprint-tests in ember-cli-legacy-blueprints to node-tests folder

`target`: 'addon' with `isModuleUnification`: true looks to be not working

emberjs/ember.js#17212 upgrades Ember to [email protected] and fix the blueprint tests.

I had to skip all the in-addon - module unification tests (they are marked with TODO mu new addon), because they are not working with ([email protected] and [email protected])

When testing, I have realized that an MU addon test works if it runs in isolation (no more tests running).

I don't know exactly how to debug the blueprint-test-helpers, so any help or guidance would be appreciated.

At this moment, the issue is blocking the migration of Ember to [email protected].

cc @dcyriller

Add "testFramework" option

ember-data lately gained the ability to generate different files depending on the presence of ember-cli-qunit and/or ember-cli-mocha (see emberjs/data#4167). It would be awesome if this addon provided some sort of testFramework option defaulting to qunit that would allow ember-data to also test their mocha blueprints.

assertThrows no longer functional

It seems that this change to ember-cli: https://github.com/ember-cli/ember-cli@d79f810#diff-046dd933d1aae8e9131812190820a4c6R81
broke the assertThrows check, because we are expecting the results object rather than an actual error:
https://github.com/ember-cli/ember-cli-blueprint-test-helpers/blob/master/lib/helpers/blueprint-helper.js#L245

Anyhow, we need to properly assert using chai-as-promised for it to work now that we're receiving an error instead of a results object.

Remove tmp-sync from dependencies

tmp-sync relies on an older version of lodash and is included transitively through other Ember projects as a result.

I'm currently investigating other options, but it appears that tmp may be a valid replacement ignoring the dependency on os-tmp which was deprecated for Node 4.x+ in favor of os.tmpdir

I've submitted a PR to tmp-sync to try and upgrade their dependency on fs-sync which includes the older version of Lodash, but it's been without updates for a few years so I'm not optimistic that it sees the light of day.

Thanks for your time in reading!

ember-cli-shims error

I'm seeing the ember-cli-shims-versions-prior-to-0.1.0 error when running Ember Simple Auth's blueprint tests with Ember/Ember Data/Ember CLI 2.4.x:

1) Acceptance: ember generate and destroy authenticator generates an OAuth 2.0 authenticator:
     Error: the object {
  "errorLog": [
    {
      "isSilentError": true
      "message": "Using a version of ember-cli-shims prior to 0.1.0 will cause errors while loading Ember Data 2.3.0-beta.3+. Please update ember-cli-shims from undefined to 0.1.0."
      "name": "SilentError"
      "suppressedStacktrace": true
    }
  ]
  "exitCode": 1
  "inputStream": []
  "outputStream": []
  "statusCode": 1
} was thrown, throw an Error :)

I'm not sure whether that's a bug in this library or something wrong with the way it's being used in ESA but I was under the impression that bower is skipped in the temp project that the blueprints are run in anyway so that it shouldn't have ember-cli-shims at all?

This pull request has the code that updates Ember CLI et al in ESA with the failing tests: mainmatter/ember-simple-auth#918

An in-range update of rsvp is breaking the build 🚨

Version 3.5.0 of rsvp just got published.

Branch Build failing 🚨
Dependency rsvp
Current Version 3.4.0
Type dependency

This version is covered by your current version range and after updating it in your project the build failed.

As rsvp is a direct dependency of this project this is very likely breaking your project right now. If other packages depend on you it’s very likely also breaking them.
I recommend you give this issue a very high priority. I’m sure you can resolve this 💪


Status Details
  • continuous-integration/travis-ci/push The Travis CI build failed Details

  • continuous-integration/appveyor/branch AppVeyor build succeeded Details

Commits

The new version differs by 5 commits .

  • 3b75eb7 release v3.5.0
  • da93e2d Merge pull request #449 from tildeio/asap
  • b58bfb1 expose RSVP.asap as public API
  • fa5bee3 Merge pull request #448 from tildeio/fix-node-4
  • 0465ffa Fix node 4 on CI

See the full diff.

Not sure how things should work exactly?

There is a collection of frequently asked questions and of course you may always ask my humans.


Your Greenkeeper Bot 🌴

An in-range update of ember-cli is breaking the build 🚨

Version 2.12.0 of ember-cli just got published.

Branch Build failing 🚨
Dependency ember-cli
Current Version 2.11.1
Type devDependency

This version is covered by your current version range and after updating it in your project the build failed.

As ember-cli is “only” a devDependency of this project it might not break production or downstream projects, but “only” your build or test tools – preventing new deploys or publishes.

I recommend you give this issue a high priority. I’m sure you can resolve this 💪


Status Details
  • continuous-integration/appveyor/branch AppVeyor build succeeded Details

  • continuous-integration/travis-ci/push The Travis CI build could not complete due to an error Details

Release Notes le train à paris

Setup

  1. npm uninstall -g ember-cli -- Remove old global ember-cli
  2. npm cache clean -- Clear NPM cache
  3. bower cache clean -- Clear Bower cache
  4. npm install -g [email protected] -- Install new global ember-cli

Project Update

  1. rm -rf node_modules bower_components dist tmp -- Delete temporary development folders.
  2. npm install --save-dev [email protected] -- Update project's package.json to use latest version.
  3. npm install -- Reinstall NPM dependencies.
  4. bower install -- Reinstall bower dependencies.
  5. ember init -- This runs the new project blueprint on your projects directory. Please follow the prompts, and review all changes (tip: you can see a diff by pressing d). The most common source of upgrade pain is missing changes in this step.

Changelog

The following changes are required if you are upgrading from the previous
version:

Community Contributions

Thank you to all who took the time to contribute!

Not sure how things should work exactly?

There is a collection of frequently asked questions and of course you may always ask my humans.


Your Greenkeeper Bot 🌴

emberNew inside scoped npm package

My addon is a scoped npm package with a name like @scope/addon-name.
When using emberNew() this results in the following error:

Error: ENOENT: no such file or directory, symlink 'C:\[SNIP]\addon-name' -> 'C:\[SNIP]\addon-name\node_modules\@scope\addon-name'

This could be fixed by using the get-package-base-name utility from ember-cli:

//ember-cli-blueprint-test-helpers/lib/ember-new.js
...
// inside function linkAddon() {

  var projectName = require(path.resolve(projectPath, 'package.json')).name;
  projectName = require('ember-cli/lib/utilities/get-package-base-name')(projectName); // add this line
...

Please let me know if more information is needed.

releasing

Could a maintainer release a version containing the last PRs please?

It would be easier to use than targetting master...

Missing Peer Dependencies

Recently realized that this package requires monorepos to install ember-cli etc. at the root in order to deal with it not declaring a peer-dep on ember-cli.

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.