Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: avajs/ava
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v2.1.0
Choose a base ref
...
head repository: avajs/ava
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v2.2.0
Choose a head ref
  • 9 commits
  • 23 files changed
  • 5 contributors

Commits on Jun 23, 2019

  1. Remove Flow references

    langri-sha authored and novemberborn committed Jun 23, 2019

    Unverified

    This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
    Copy the full SHA
    851316f View commit details
  2. Fix grammar in readme

    keyspress authored and novemberborn committed Jun 23, 2019

    Unverified

    This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
    Copy the full SHA
    dc91725 View commit details
  3. Link to VSCode debugging recipe

    cdaringe authored and novemberborn committed Jun 23, 2019

    Unverified

    This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
    Copy the full SHA
    533ee4b View commit details

Commits on Jul 7, 2019

  1. Unverified

    This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
    Copy the full SHA
    90acbb9 View commit details
  2. Fake hasColors() in worker processes

    Fixes #2170.
    oantoro authored and novemberborn committed Jul 7, 2019

    Unverified

    This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
    Copy the full SHA
    d399797 View commit details
  3. Unverified

    This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
    Copy the full SHA
    58b2350 View commit details
  4. Implement --config flag

    Fixes #1857.
    novemberborn authored Jul 7, 2019

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    2dae2bf View commit details

Commits on Jul 8, 2019

  1. Bump dependencies

    novemberborn authored Jul 8, 2019

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    e528ad2 View commit details
  2. 2.2.0

    novemberborn committed Jul 8, 2019

    Verified

    This commit was signed with the committer’s verified signature.
    novemberborn Mark Wubben
    Copy the full SHA
    2451484 View commit details
5 changes: 0 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -8,7 +8,6 @@ os:
- linux
node_js:
- 12
- 11
- 10
- 8
env:
@@ -22,10 +21,6 @@ matrix:
- node_js: 12
env: FRESH_DEPS=false
os: linux # Windows already tests without fresh dependencies, and we test *with* on Linux.
- node_js: 11
os: windows # We don't need to test odd-version releases very hard.
- node_js: 11
env: FRESH_DEPS=true
- node_js: 10
env: FRESH_DEPS=true
- node_js: 8
2 changes: 2 additions & 0 deletions docs/05-command-line.md
Original file line number Diff line number Diff line change
@@ -21,6 +21,8 @@ $ npx ava --help
--color Force color output
--no-color Disable color output
--reset-cache Reset AVA's compilation cache and exit
--config JavaScript file for AVA to read its config from, instead of using package.json
or ava.config.js files

Examples
ava
33 changes: 32 additions & 1 deletion docs/06-configuration.md
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@

Translations: [Français](https://github.com/avajs/ava-docs/blob/master/fr_FR/docs/06-configuration.md)

All of the [CLI options](./05-command-line.md) can be configured in the `ava` section of either your `package.json` file, or an `ava.config.js` file. This allows you to modify the default behavior of the `ava` command, so you don't have to repeatedly type the same options on the command prompt.
All of the [CLI options][CLI] can be configured in the `ava` section of either your `package.json` file, or an `ava.config.js` file. This allows you to modify the default behavior of the `ava` command, so you don't have to repeatedly type the same options on the command prompt.

To ignore files, prefix the pattern with an `!` (exclamation mark).

@@ -115,6 +115,35 @@ export default ({projectDir}) => {

Note that the final configuration must not be a promise.

## Alternative configuration files

The [CLI] lets you specify a specific configuration file, using the `--config` flag. This file is processed just like an `ava.config.js` file would be. When the `--config` flag is set, the provided file will override all configuration from the `package.json` and `ava.config.js` files. The configuration is not merged.

The configuration file *must* be in the same directory as the `package.json` file.

You can use this to customize configuration for a specific test run. For instance, you may want to run unit tests separately from integration tests:

`ava.config.js`:

```js
export default {
files: ['unit-tests/**/*']
};
```

`integration-tests.config.js`:

```js
import baseConfig from './ava.config.js';

export default {
...baseConfig,
files: ['integration-tests/**/*']
};
```

You can now run your unit tests through `npx ava` and the integration tests through `npx ava --config integration-tests.config.js`.

## Object printing depth

By default, AVA prints nested objects to a depth of `3`. However, when debugging tests with deeply nested objects, it can be useful to print with more detail. This can be done by setting [`util.inspect.defaultOptions.depth`](https://nodejs.org/api/util.html#util_util_inspect_defaultoptions) to the desired depth, before the test is executed:
@@ -132,3 +161,5 @@ test('My test', t => {
```

AVA has a minimum depth of `3`.

[CLI]: ./05-command-line.md
2 changes: 1 addition & 1 deletion docs/recipes/typescript.md
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@ Translations: [Español](https://github.com/avajs/ava-docs/blob/master/es_ES/doc

AVA comes bundled with a TypeScript definition file. This allows developers to leverage TypeScript for writing tests.

This guide assumes you've already set up TypeScript for your project. Note that AVA's definition has been tested with version 3.5.1.
This guide assumes you've already set up TypeScript for your project. Note that AVA's definition has been tested with version 3.5.2.

## Configuring AVA to compile TypeScript files on the fly

2 changes: 1 addition & 1 deletion eslint-plugin-helper.js
Original file line number Diff line number Diff line change
@@ -18,7 +18,7 @@ function load(projectDir, overrides) {
if (configCache.has(projectDir)) {
({conf, babelConfig} = configCache.get(projectDir));
} else {
conf = loadConfig(projectDir);
conf = loadConfig({resolveFrom: projectDir});
babelConfig = babelPipeline.validate(conf.babel);
configCache.set(projectDir, {conf, babelConfig});
}
13 changes: 11 additions & 2 deletions lib/cli.js
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@ const arrify = require('arrify');
const meow = require('meow');
const Promise = require('bluebird');
const isCi = require('is-ci');
const loadConf = require('./load-config');
const loadConfig = require('./load-config');

// Bluebird specific
Promise.longStackTraces();
@@ -18,10 +18,17 @@ function exit(message) {
}

exports.run = async () => { // eslint-disable-line complexity
const {flags: {config: configFile}} = meow({ // Process the --config flag first
autoHelp: false, // --help should get picked up by the next meow invocation.
flags: {
config: {type: 'string'}
}
});

let conf = {};
let confError = null;
try {
conf = loadConf();
conf = loadConfig({configFile});
} catch (error) {
confError = error;
}
@@ -43,6 +50,8 @@ exports.run = async () => { // eslint-disable-line complexity
--color Force color output
--no-color Disable color output
--reset-cache Reset AVA's compilation cache and exit
--config JavaScript file for AVA to read its config from, instead of using package.json
or ava.config.js files
Examples
ava
1 change: 1 addition & 0 deletions lib/fork.js
Original file line number Diff line number Diff line change
@@ -25,6 +25,7 @@ if (process.env.NODE_PATH) {

const describeTTY = tty => ({
colorDepth: tty.getColorDepth ? tty.getColorDepth() : undefined,
hasColors: typeof tty.hasColors === 'function',
columns: tty.columns || 80,
rows: tty.rows
});
8 changes: 4 additions & 4 deletions lib/globs.js
Original file line number Diff line number Diff line change
@@ -98,17 +98,17 @@ exports.hasExtension = hasExtension;
const findFiles = async (cwd, patterns) => {
const files = await globby(patterns, {
absolute: true,
brace: true,
case: false,
braceExpansion: true,
caseSensitiveMatch: false,
cwd,
dot: false,
expandDirectories: false,
extglob: true,
followSymlinkedDirectories: true,
followSymbolicLinks: true,
gitignore: false,
globstar: true,
ignore: defaultIgnorePatterns,
matchBase: false,
baseNameMatch: false,
onlyFiles: true,
stats: false,
unique: true
38 changes: 26 additions & 12 deletions lib/load-config.js
Original file line number Diff line number Diff line change
@@ -7,11 +7,23 @@ const pkgConf = require('pkg-conf');
const NO_SUCH_FILE = Symbol('no ava.config.js file');
const MISSING_DEFAULT_EXPORT = Symbol('missing default export');

function loadConfig(resolveFrom = process.cwd(), defaults = {}) {
const packageConf = pkgConf.sync('ava', {cwd: resolveFrom});
function loadConfig({configFile, resolveFrom = process.cwd(), defaults = {}} = {}) { // eslint-disable-line complexity
let packageConf = pkgConf.sync('ava', {cwd: resolveFrom});
const filepath = pkgConf.filepath(packageConf);
const projectDir = filepath === null ? resolveFrom : path.dirname(filepath);

const fileForErrorMessage = configFile || 'ava.config.js';
const allowConflictWithPackageJson = Boolean(configFile);

if (configFile) {
configFile = path.resolve(configFile); // Relative to CWD
if (path.basename(configFile) !== path.relative(projectDir, configFile)) {
throw new Error('Config files must be located next to the package.json file');
}
} else {
configFile = path.join(projectDir, 'ava.config.js');
}

let fileConf;
try {
({default: fileConf = MISSING_DEFAULT_EXPORT} = esm(module, {
@@ -26,45 +38,47 @@ function loadConfig(resolveFrom = process.cwd(), defaults = {}) {
},
force: true,
mode: 'all'
})(path.join(projectDir, 'ava.config.js')));
})(configFile));
} catch (error) {
if (error && error.code === 'MODULE_NOT_FOUND') {
fileConf = NO_SUCH_FILE;
} else {
throw Object.assign(new Error('Error loading ava.config.js'), {parent: error});
throw Object.assign(new Error(`Error loading ${fileForErrorMessage}`), {parent: error});
}
}

if (fileConf === MISSING_DEFAULT_EXPORT) {
throw new Error('ava.config.js must have a default export, using ES module syntax');
throw new Error(`${fileForErrorMessage} must have a default export, using ES module syntax`);
}

if (fileConf !== NO_SUCH_FILE) {
if (Object.keys(packageConf).length > 0) {
throw new Error('Conflicting configuration in ava.config.js and package.json');
if (allowConflictWithPackageJson) {
packageConf = {};
} else if (Object.keys(packageConf).length > 0) {
throw new Error(`Conflicting configuration in ${fileForErrorMessage} and package.json`);
}

if (fileConf && typeof fileConf.then === 'function') { // eslint-disable-line promise/prefer-await-to-then
throw new TypeError('ava.config.js must not export a promise');
throw new TypeError(`${fileForErrorMessage} must not export a promise`);
}

if (!isPlainObject(fileConf) && typeof fileConf !== 'function') {
throw new TypeError('ava.config.js must export a plain object or factory function');
throw new TypeError(`${fileForErrorMessage} must export a plain object or factory function`);
}

if (typeof fileConf === 'function') {
fileConf = fileConf({projectDir});
if (fileConf && typeof fileConf.then === 'function') { // eslint-disable-line promise/prefer-await-to-then
throw new TypeError('Factory method exported by ava.config.js must not return a promise');
throw new TypeError(`Factory method exported by ${fileForErrorMessage} must not return a promise`);
}

if (!isPlainObject(fileConf)) {
throw new TypeError('Factory method exported by ava.config.js must return a plain object');
throw new TypeError(`Factory method exported by ${fileForErrorMessage} must return a plain object`);
}
}

if ('ava' in fileConf) {
throw new Error('Encountered \'ava\' property in ava.config.js; avoid wrapping the configuration');
throw new Error(`Encountered 'ava' property in ${fileForErrorMessage}; avoid wrapping the configuration`);
}
}

19 changes: 19 additions & 0 deletions lib/worker/fake-tty-has-colors.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
'use strict';
const tty = require('tty');

// Call original method to ensure the correct errors are thrown.
const assertHasColorsArguments = count => {
tty.WriteStream.prototype.hasColors(count);
};

const makeHasColors = colorDepth => (count = 16, env) => {
// `count` is optional too, so make sure it's not an env object.
if (env === undefined && typeof count === 'object' && count !== null) {
count = 16;
}

assertHasColorsArguments(count);
return count <= 2 ** colorDepth;
};

module.exports = makeHasColors;
7 changes: 6 additions & 1 deletion lib/worker/fake-tty.js
Original file line number Diff line number Diff line change
@@ -2,13 +2,14 @@
const tty = require('tty');
const ansiEscapes = require('ansi-escapes');
const options = require('./options').get();
const makeHasColors = require('./fake-tty-has-colors');

const fakeTTYs = new Set();

const {isatty} = tty;
tty.isatty = fd => fakeTTYs.has(fd) || isatty(fd);

const simulateTTY = (stream, {colorDepth, columns, rows}) => {
const simulateTTY = (stream, {colorDepth, hasColors, columns, rows}) => {
Object.assign(stream, {isTTY: true, columns, rows});

stream.clearLine = dir => {
@@ -35,6 +36,10 @@ const simulateTTY = (stream, {colorDepth, columns, rows}) => {
if (colorDepth !== undefined) {
stream.getColorDepth = () => colorDepth;
}

if (hasColors) {
stream.hasColors = makeHasColors(colorDepth);
}
};

if (options.tty.stderr) {
Loading