1.0.7 • Published 5 years ago

testcafe-mock-recorder v1.0.7

Weekly downloads
89
License
ISC
Repository
-
Last release
5 years ago

MockDataRecorder

A simple JS library that allow us to automatically record the JSON data from API calls when running E2E tests via testcafe.

Installation

npm install testcafe-mock-recorder

Usage

import { Selector, RequestLogger } from 'testcafe'
import Recorder from 'testcafe-mock-recorder'

fixture `Getting Started`
  .page `https://github.com`

test('My first test', async t => {
  const testcafeRecorder = new Recorder({
    RequestLogger,
    predicate: request => {
      const captureRegExp = /.*/
      const excludeRegExp = /exclude_this_pattern/
      return captureRegExp.test(request.url) && !excludeRegExp.test(request.url)
    },
    record: true, 
    baseDir: __dirname
  })
  await testcafeRecorder.startRecording(t)
  await t
    .wait(5000)
  testcafeRecorder.writeMockData('testFile.js')
})

Import mock data file

import { Selector, RequestLogger } from 'testcafe'
import Recorder from 'testcafe-mock-recorder'
// import autogenerated file
import testFileData from './testFile'

fixture `Getting Started`
  .page `https://github.com`

test('My first test', async t => {
  const testcafeRecorder = new Recorder({
    RequestLogger,
    predicate: request => {
      const captureRegExp = /.*/
      const excludeRegExp = /exclude_this_pattern/
      return captureRegExp.test(request.url) && !excludeRegExp.test(request.url)
    },
    record: false, // set record option to false (we don't want to re-write the file)
    baseDir: __dirname
  })
  await testcafeRecorder.startRecording(t, testFileData.all) // we set the mocks here to detach them if we want to update the data when {record: true}
  await t
    .wait(5000)
  testcafeRecorder.writeMockData('testFile.js')
}).requestHooks(testFileData.all) // attach the mocks to the test

Want to contribute, feedback, questions?

Github: https://github.com/gralmurdok/testcafeMockRecorder

1.0.7

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.0

6 years ago