Skip to content

Commit

Permalink
Merge branch 'master' into add-freeze-core-modules-configuration-option
Browse files Browse the repository at this point in the history
  • Loading branch information
lev-kazakov committed Apr 24, 2019
2 parents 7bee921 + 4d3c1a1 commit 105fc9b
Show file tree
Hide file tree
Showing 69 changed files with 1,742 additions and 1,868 deletions.
10 changes: 8 additions & 2 deletions .azure-pipelines-steps.yml
Expand Up @@ -26,9 +26,15 @@ steps:
displayName: 'Move source into jest folder'
# Run yarn to install dependencies and build
- script: yarn --frozen-lockfile
- script: node scripts/remove-postinstall
workingDirectory: $(JEST_DIR)
displayName: 'Install dependencies and build'
displayName: 'Remove postinstall script'
- script: yarn --no-progress --frozen-lockfile
workingDirectory: $(JEST_DIR)
displayName: 'Install dependencies'
- script: node scripts/build
workingDirectory: $(JEST_DIR)
displayName: 'Build'

# Run test-ci-partial
- script: yarn run test-ci-partial
Expand Down
15 changes: 8 additions & 7 deletions .circleci/config.yml
Expand Up @@ -14,6 +14,7 @@ aliases:
- &filter-ignore-gh-pages
branches:
ignore: gh-pages
- &install node scripts/remove-postinstall && yarn --no-progress --frozen-lockfile --ignore-engines && node scripts/build

version: 2
jobs:
Expand All @@ -37,7 +38,7 @@ jobs:
steps:
- checkout
- restore-cache: *restore-cache
- run: yarn --no-progress --frozen-lockfile --ignore-engines
- run: *install
- save-cache: *save-cache
- run:
# react-native does not work with node 6
Expand All @@ -52,7 +53,7 @@ jobs:
steps:
- checkout
- restore-cache: *restore-cache
- run: yarn --no-progress --frozen-lockfile
- run: *install
- save-cache: *save-cache
- run:
command: yarn test-ci-partial
Expand All @@ -66,7 +67,7 @@ jobs:
steps:
- checkout
- restore-cache: *restore-cache
- run: yarn --no-progress --frozen-lockfile
- run: *install
- save-cache: *save-cache
- run:
command: yarn test-ci
Expand All @@ -80,7 +81,7 @@ jobs:
steps:
- checkout
- restore-cache: *restore-cache
- run: yarn --no-progress --frozen-lockfile
- run: *install
- save-cache: *save-cache
- run:
command: JEST_CIRCUS=1 yarn test-ci-partial
Expand All @@ -94,7 +95,7 @@ jobs:
steps:
- checkout
- restore-cache: *restore-cache
- run: yarn --no-progress --frozen-lockfile
- run: *install
- save-cache: *save-cache
- run:
command: yarn test-ci-partial
Expand All @@ -108,7 +109,7 @@ jobs:
steps:
- checkout
- restore-cache: *restore-cache
- run: yarn --no-progress --frozen-lockfile
- run: *install
- save-cache: *save-cache
- run: yarn test-ci-es5-build-in-browser

Expand All @@ -120,7 +121,7 @@ jobs:
steps:
- checkout
- restore-cache: *restore-cache
- run: yarn --no-progress --frozen-lockfile
- run: *install
- save-cache: *save-cache
- run:
name: Test or Deploy Jest Website
Expand Down
2 changes: 1 addition & 1 deletion .travis.yml
Expand Up @@ -11,7 +11,7 @@ before_install:
- curl -o- -L https://yarnpkg.com/install.sh | bash
- export PATH="$HOME/.yarn/bin:$PATH"

install: yarn --frozen-lockfile
install: node scripts/remove-postinstall && yarn --no-progress --frozen-lockfile --ignore-engines && node scripts/build

cache:
yarn: true
Expand Down
11 changes: 11 additions & 0 deletions CHANGELOG.md
Expand Up @@ -3,21 +3,32 @@
### Features

- `[jest-config]` Add `freezeCoreModules` configuration option to mitigate memory leaks described in the following issues: [#6399](https://github.com/facebook/jest/issues/6399), [#6814](https://github.com/facebook/jest/issues/6814) ([#8331](https://github.com/facebook/jest/pull/8331))
- `[jest-circus]` Bind to Circus events via an optional event handler on any custom env ([#8344](https://github.com/facebook/jest/pull/8344)
- `[expect]` Improve report when matcher fails, part 15 ([#8281](https://github.com/facebook/jest/pull/8281))
- `[jest-cli]` Update `--forceExit` and "did not exit for one second" message colors ([#8329](https://github.com/facebook/jest/pull/8329))
- `[expect]` Improve report when matcher fails, part 16 ([#8306](https://github.com/facebook/jest/pull/8306))
- `[jest-runner]` Pass docblock pragmas to TestEnvironment constructor ([#8320](https://github.com/facebook/jest/pull/8320))
- `[docs]` Add DynamoDB guide ([#8319](https://github.com/facebook/jest/pull/8319))
- `[expect]` Improve report when matcher fails, part 17 ([#8349](https://github.com/facebook/jest/pull/8349))
- `[expect]` Improve report when matcher fails, part 18 ([#8356](https://github.com/facebook/jest/pull/8356))

### Fixes

- `[jest-each]` Fix bug with placeholder values ([#8289](https://github.com/facebook/jest/pull/8289))
- `[jest-snapshot]` Inline snapshots: do not indent empty lines ([#8277](https://github.com/facebook/jest/pull/8277))
- `[@jest/runtime, @jest/transform]` Allow custom transforms for JSON dependencies ([#2578](https://github.com/facebook/jest/pull/2578))
- `[jest-core]` Make `detectOpenHandles` imply `runInBand` ([#8283](https://github.com/facebook/jest/pull/8283))
- `[jest-haste-map]` Fix the `mapper` option which was incorrectly ignored ([#8299](https://github.com/facebook/jest/pull/8299))
- `[jest-jasmine2]` Fix describe return value warning being shown if the describe function throws ([#8335](https://github.com/facebook/jest/pull/8335))
- `[jest-environment-jsdom]` Re-declare global prototype of JSDOMEnvironment ([#8352](https://github.com/facebook/jest/pull/8352))
- `[jest-snapshot]` Handle arrays when merging snapshots ([#7089](https://github.com/facebook/jest/pull/7089))
- `[expect]` Extract names of async and generator functions ([#8362](https://github.com/facebook/jest/pull/8362))

### Chore & Maintenance

- `[expect]` Fix label and add opposite assertion for toEqual tests ([#8288](https://github.com/facebook/jest/pull/8288))
- `[docs]` Mention Jest MongoDB Preset ([#8318](https://github.com/facebook/jest/pull/8318))
- `[@jest/reporters]` Migrate away from `istanbul-api` ([#8294](https://github.com/facebook/jest/pull/8294))

### Performance

Expand Down
8 changes: 8 additions & 0 deletions docs/Configuration.md
Expand Up @@ -877,6 +877,8 @@ test('use jsdom in this test file', () => {

You can create your own module that will be used for setting up the test environment. The module must export a class with `setup`, `teardown` and `runScript` methods. You can also pass variables from this module to your test suites by assigning them to `this.global` object – this will make them available in your test suites as global variables.

The class may optionally expose a `handleTestEvent` method to bind to events fired by [`jest-circus`](https://github.com/facebook/jest/tree/master/packages/jest-circus).

Any docblock pragmas in test files will be passed to the environment constructor and can be used for per-test configuration. If the pragma does not have a value, it will be present in the object with it's value set to an empty string. If the pragma is not present, it will not be present in the object.

_Note: TestEnvironment is sandboxed. Each test suite will trigger setup/teardown in their own TestEnvironment._
Expand Down Expand Up @@ -914,6 +916,12 @@ class CustomEnvironment extends NodeEnvironment {
runScript(script) {
return super.runScript(script);
}

handleTestEvent(event, state) {
if (event.name === 'test_start') {
// ...
}
}
}

module.exports = CustomEnvironment;
Expand Down
81 changes: 81 additions & 0 deletions docs/DynamoDB.md
@@ -0,0 +1,81 @@
---
id: dynamodb
title: Using with DynamoDB
---

With the [Global Setup/Teardown](Configuration.md#globalsetup-string) and [Async Test Environment](Configuration.md#testenvironment-string) APIs, Jest can work smoothly with [DynamoDB](https://aws.amazon.com/dynamodb/).

## Use jest-dynamodb Preset

[Jest DynamoDB](https://github.com/shelfio/jest-dynamodb) provides all required configuration to run your tests using DynamoDB.

1. First install `@shelf/jest-dynamodb`

```
yarn add @shelf/jest-dynamodb --dev
```

2. Specify preset in your Jest configuration:

```json
{
"preset": "@shelf/jest-dynamodb"
}
```

3. Create `jest-dynamodb-config.js` and define DynamoDB tables

See [Create Table API](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/DynamoDB.html#createTable-property)

```js
module.exports = {
tables: [
{
TableName: `files`,
KeySchema: [{AttributeName: 'id', KeyType: 'HASH'}],
AttributeDefinitions: [{AttributeName: 'id', AttributeType: 'S'}],
ProvisionedThroughput: {ReadCapacityUnits: 1, WriteCapacityUnits: 1},
},
// etc
],
};
```

4. Configure DynamoDB client

```js
const {DocumentClient} = require('aws-sdk/clients/dynamodb');

const isTest = process.env.JEST_WORKER_ID;
const config = {
convertEmptyValues: true,
...(isTest && {
endpoint: 'localhost:8000',
sslEnabled: false,
region: 'local-env',
}),
};

const ddb = new DocumentClient(config);
```

5. Write tests

```js
it('should insert item into table', async () => {
await ddb
.put({TableName: 'files', Item: {id: '1', hello: 'world'}})
.promise();

const {Item} = await ddb.get({TableName: 'files', Key: {id: '1'}}).promise();

expect(Item).toEqual({
id: '1',
hello: 'world',
});
});
```

There's no need to load any dependencies.

See [documentation](https://github.com/shelfio/jest-dynamodb) for details.
8 changes: 1 addition & 7 deletions docs/MigrationGuide.md
Expand Up @@ -13,16 +13,10 @@ If you'd like to try out Jest with an existing codebase, there are a number of w

If you are using [AVA](https://github.com/avajs/ava), [Chai](https://github.com/chaijs/chai), [Expect.js (by Automattic)](https://github.com/Automattic/expect.js), [Jasmine](https://github.com/jasmine/jasmine), [Mocha](https://github.com/mochajs/mocha), [proxyquire](https://github.com/thlorenz/proxyquire), [Should.js](https://github.com/shouldjs/should.js) or [Tape](https://github.com/substack/tape) you can use the third-party [jest-codemods](https://github.com/skovhus/jest-codemods) to do most of the dirty migration work. It runs a code transformation on your codebase using [jscodeshift](https://github.com/facebook/jscodeshift).

Install Jest Codemods with `yarn` by running:

```bash
yarn global add jest-codemods
```

To transform your existing tests, navigate to the project containing the tests and run:

```bash
jest-codemods
npx jest-codemods
```

More information can be found at [https://github.com/skovhus/jest-codemods](https://github.com/skovhus/jest-codemods).

0 comments on commit 105fc9b

Please sign in to comment.