1 | # ember-try
|
2 |
|
3 | [![npm version](https://badge.fury.io/js/ember-try.svg)](https://badge.fury.io/js/ember-try) [![GitHub Actions Build Status](https://github.com/ember-cli/ember-try/workflows/CI/badge.svg)](https://github.com/ember-cli/ember-try/actions/workflows/ci.yml?query=branch%3Amaster) [![Ember Observer Score](http://emberobserver.com/badges/ember-try.svg)](http://emberobserver.com/addons/ember-try) [![Build status](https://ci.appveyor.com/api/projects/status/9sswkni8pfuvo4dv/branch/master?svg=true)](https://ci.appveyor.com/project/kategengler/ember-try/branch/master) [![Code Climate](https://codeclimate.com/github/ember-cli/ember-try/badges/gpa.svg)](https://codeclimate.com/github/ember-cli/ember-try) [![Test Coverage](https://codecov.io/gh/ember-cli/ember-try/branch/master/graph/badge.svg)](https://codecov.io/gh/ember-cli/ember-try)
|
4 |
|
5 | An ember-cli addon to test against multiple dependencies, such as `ember` and `ember-data`.
|
6 |
|
7 | ### Installation
|
8 |
|
9 | ```
|
10 | ember install ember-try
|
11 | ```
|
12 |
|
13 | ### Usage
|
14 |
|
15 | This addon provides a few commands:
|
16 |
|
17 | ### `ember try:each`
|
18 |
|
19 | This command will run `ember test` or the configured command with each scenario's specified in the config and exit appropriately.
|
20 |
|
21 | This command is especially useful to use on CI to test against multiple `ember` versions.
|
22 |
|
23 | In order to use an alternate config path or to group various scenarios together in a single `try:each` run, you can use
|
24 | the `--config-path` option.
|
25 |
|
26 | ```
|
27 | ember try:each --config-path="config/legacy-scenarios.js"
|
28 | ```
|
29 |
|
30 | If you need to know the scenario that is being run (i.e. to customize a test output file name) you can use the `EMBER_TRY_CURRENT_SCENARIO`
|
31 | environment variable.
|
32 |
|
33 | #### `ember try:one <scenario> (...options) --- <command (Default: ember test)>`
|
34 |
|
35 | This command will run any `ember-cli` command with the specified scenario. The command will default to `ember test`, if no command is specified on the command-line or in configuration.
|
36 |
|
37 | For example:
|
38 |
|
39 | ```
|
40 | ember try:one ember-1.11-with-ember-data-beta-16 --- ember test --reporter xunit
|
41 | ```
|
42 |
|
43 | or
|
44 |
|
45 | ```
|
46 | ember try:one ember-1.11-with-ember-data-beta-16 --- ember serve
|
47 | ```
|
48 |
|
49 | When running in a CI environment where changes are discarded you can skip resetting your environment back to its original state by specifying --skip-cleanup=true as an option to ember try.
|
50 | *Warning: If you use this option and, without cleaning up, build and deploy as the result of a passing test suite, it will build with the last set of dependencies ember try was run with.*
|
51 |
|
52 | ```
|
53 | ember try:one ember-1.11 --skip-cleanup=true --- ember test
|
54 | ```
|
55 |
|
56 | In order to use an alternate config path or to group various scenarios, you can use the `--config-path` option.
|
57 |
|
58 | ```
|
59 | ember try:one ember-1.13 --config-path="config/legacy-scenarios.js"
|
60 | ```
|
61 |
|
62 | #### `ember try:reset`
|
63 |
|
64 | This command restores the original `package.json` from `package.json.ember-try`, `rm -rf`s `node_modules` and runs `npm install`. For use if any of the other commands fail to clean up after (they run this by default on completion).
|
65 |
|
66 | #### `ember try:ember <semver-string>`
|
67 |
|
68 | Runs `ember test` or the command in config for each version of Ember that is possible under the semver string given. Configuration follows the rules given under the `versionCompatibility` heading below.
|
69 |
|
70 | #### `ember try:config`
|
71 |
|
72 | Displays the configuration that will be used. Also takes an optional `--config-path`.
|
73 |
|
74 | ### Config
|
75 |
|
76 | ##### versionCompatibility
|
77 | If you're using `ember-try` with an Ember addon, there is a short cut to test many Ember versions. In your `package.json` under the `ember-addon` key, add the following:
|
78 |
|
79 | ```json
|
80 | "ember-addon": {
|
81 | "versionCompatibility": {
|
82 | "ember": ">2.18.0 < 4.0.0"
|
83 | }
|
84 | }
|
85 | ```
|
86 |
|
87 | The value for "ember" can be any valid [semver statement](https://github.com/npm/node-semver).
|
88 | This will autogenerate scenarios for each version of Ember that matches the statement. It will also include scenarios for `beta` and `canary` channels of Ember that will be allowed to fail.
|
89 | These scenarios will ONLY be used if `scenarios` is NOT a key in the configuration file being used.
|
90 | If `useVersionCompatibility` is set to `true` in the config file, the autogenerated scenarios will deep merge with any scenarios in the config file. For example, you could override just the `allowedToFail` property of the `ember-beta` scenario.
|
91 |
|
92 | To keep this from getting out of hand, `ember-try` will limit the versions of Ember used to the lasted point release per minor version. For example, ">1.11.0 <=2.0.0", would (as of writing) run with versions ['1.11.4', '1.12.2', '1.13.13', '2.0.0'].
|
93 |
|
94 | ##### Configuration Files
|
95 |
|
96 | Configuration will be read from a file in your ember app in `config/ember-try.js`. Here are the possible options:
|
97 |
|
98 | ```js
|
99 | const getChannelURL = require('ember-source-channel-url');
|
100 |
|
101 | module.exports = async function() {
|
102 | return {
|
103 | /*
|
104 | `command` - a single command that, if set, will be the default command used by `ember-try`.
|
105 | P.S. The command doesn't need to be an `ember <something>` command, they can be anything.
|
106 | Keep in mind that this config file is JavaScript, so you can code in here to determine the command.
|
107 | */
|
108 | command: 'ember test --reporter xunit',
|
109 | /*
|
110 | `npmOptions` - options to be passed to `npm`.
|
111 | */
|
112 | npmOptions: ['--loglevel=silent', '--no-shrinkwrap=true'],
|
113 | /*
|
114 | If set to true, the `versionCompatibility` key under `ember-addon` in `package.json` will be used to
|
115 | automatically generate scenarios that will deep merge with any in this configuration file.
|
116 | */
|
117 | useVersionCompatibility: true,
|
118 | /*
|
119 | If set to true, all npm scenarios will use `yarn` for install with the `--no-lockfile` option. At cleanup, your
|
120 | dependencies will be restored to their prior state.
|
121 | */
|
122 | useYarn: true,
|
123 | /*
|
124 | If set to true, all npm scenarios will use `pnpm` for install with the `--no-lockfile` options. At cleanup, your
|
125 | dependencies will be restored to their prior state.
|
126 | */
|
127 | usePnpm: true,
|
128 |
|
129 | /*
|
130 | buildManagerOptions allows you to opt-out of the default options such as `--ignore-engines --no-lockfile`.
|
131 | The buildManagerOptions function is aware of each scenario so you can customize your options.
|
132 | */
|
133 | buildManagerOptions(scenario) {
|
134 | return ['--ignore-engines'];
|
135 | }
|
136 |
|
137 | scenarios: [
|
138 | {
|
139 | name: 'Ember 2.11.0',
|
140 | /*
|
141 | `env` can be set per scenario, with environment variables to set for the command being run.
|
142 | This will be merged with process.env
|
143 | */
|
144 | env: {
|
145 | ENABLE_NEW_DASHBOARD: true
|
146 | },
|
147 | npm: {
|
148 | devDependencies: {
|
149 | 'ember-source': '2.11.0'
|
150 | },
|
151 | /*
|
152 | You can optionally define npm or pnpm overrides to enforce a specific dependency version
|
153 | to be installed. This is useful if other libraries you depend on include different
|
154 | versions of a package. This does nothing if `useYarn` is true;
|
155 | */
|
156 | overrides: {
|
157 | 'lodash': '5.0.0'
|
158 | }
|
159 | /*
|
160 | When `useYarn` is true, you can optionally define yarn resolutions to enforce a
|
161 | specific dependency version to be installed. This is useful if other libraries
|
162 | you depend on include different versions of a package.
|
163 | */
|
164 | resolutions: {
|
165 | 'lodash': '5.0.0'
|
166 | }
|
167 | /*
|
168 | In order to easily test multiple editions ember-try merges any `ember` property specified
|
169 | into the applications `package.json`. Values specified in the ember-try configuration will
|
170 | override values that pre-existed in the original `package.json`.
|
171 | */
|
172 | ember: {
|
173 | 'edition': 'octane'
|
174 | }
|
175 | }
|
176 | },
|
177 | {
|
178 | name: 'Ember canary with Ember-Data 2.3.0',
|
179 | /*
|
180 | `allowedToFail` - If true, if this scenario fails it will not fail the entire try command.
|
181 | */
|
182 | allowedToFail: true,
|
183 | npm: {
|
184 | devDependencies: {
|
185 | 'ember-data': '2.3.0',
|
186 |
|
187 | 'ember-source': await getChannelURL('canary')
|
188 |
|
189 | // you can remove any package by marking `null`
|
190 | 'some-optional-package': null
|
191 | }
|
192 | },
|
193 | },
|
194 | {
|
195 | name: 'ember-beta',
|
196 | npm: {
|
197 | devDependencies: {
|
198 | 'ember-source': await getChannelURL('beta')
|
199 | }
|
200 | }
|
201 | },
|
202 | ]
|
203 | };
|
204 | };
|
205 | ```
|
206 |
|
207 | Scenarios are sets of dependencies. They can be specified exactly as in the `package.json`
|
208 | The `name` can be used to try just one scenario using the `ember try:one` command.
|
209 |
|
210 | ##### Yarn
|
211 |
|
212 | If you include `useYarn: true` in your `ember-try` config, all npm scenarios will use `yarn` for install with the `--no-lockfile` option. At cleanup, your dependencies will be restored to their prior state.
|
213 |
|
214 | ##### Pnpm
|
215 |
|
216 | If you include `usePnpm: true` in your `ember-try` config, all npm scenarios will use `pnpm` for install with the `--no-lockfile` options. At cleanup, your dependencies will be restored to their prior state.
|
217 |
|
218 |
|
219 | ##### A note on npm scenarios with lockfiles
|
220 |
|
221 | Lockfiles are ignored by `ember-try`. (`yarn` will run with `--no-lockfile` and `npm` will be run with `--no-shrinkwrap` and `pnpm` will be run with `--no-lockfile`).
|
222 | When testing various scenarios, it's important to "float" dependencies so that the scenarios are run with the latest satisfying versions of dependencies a user of the project would get.
|
223 |
|
224 | ##### Workspaces
|
225 |
|
226 | If you include `useWorkspaces: true` in your `ember-try` config, `ember-try` will apply the diff to each individual workspace specified
|
227 | in `package.json`, allowing you to try scenarios in monorepo style repositories. See
|
228 | [Yarn's documentation of workspaces](https://yarnpkg.com/lang/en/docs/workspaces/) for more details.
|
229 |
|
230 | ### Video
|
231 | [![How to use EmberTry](https://i.vimeocdn.com/video/559399937_500.jpg)](https://vimeo.com/157688157)
|
232 |
|
233 | See an example of using `ember-try` for CI [here](https://github.com/kategengler/ember-feature-flags/commit/aaf0226975c76630c875cf6b923fdc23b025aa79), and the resulting build [output](https://travis-ci.org/kategengler/ember-feature-flags/builds/55597086).
|
234 |
|
235 | ### Special Thanks
|
236 |
|
237 | - Much credit is due to [Edward Faulkner](https://github.com/ef4) The scripts in [liquid-fire](https://github.com/ef4/liquid-fire) that test against multiple ember versions were the inspiration for this project.
|
238 |
|
239 |
|
240 | ### Developing
|
241 |
|
242 | - Be sure to run `npm link` and `npm link ember-try`, otherwise any `ember try` commands you run will use the version of ember-try included by ember-cli itself.
|
243 |
|
\ | No newline at end of file |