Integrated chai-jest-snapshot

refs https://github.com/TryGhost/Toolbox/issues/129

- Minimal version of chai-jest-snapshot with property matcher support. It runs off the forked version of https://github.com/suchipi/chai-jest-snapshot
This commit is contained in:
Naz 2021-12-08 13:00:45 +04:00 committed by naz
parent 743b7a16e0
commit 3dfab7d682
4 changed files with 2460 additions and 1900 deletions

View File

@ -180,10 +180,13 @@
"devDependencies": { "devDependencies": {
"@lodder/grunt-postcss": "3.1.1", "@lodder/grunt-postcss": "3.1.1",
"c8": "7.10.0", "c8": "7.10.0",
"chai": "4.3.4",
"@ethanresnick/chai-jest-snapshot": "3.0.0",
"coffeescript": "2.6.1", "coffeescript": "2.6.1",
"cssnano": "5.0.12", "cssnano": "5.0.12",
"eslint": "7.32.0", "eslint": "7.32.0",
"eslint-plugin-ghost": "2.11.0", "eslint-plugin-ghost": "2.11.0",
"expect": "27.4.2",
"grunt": "1.4.1", "grunt": "1.4.1",
"grunt-bg-shell": "2.3.3", "grunt-bg-shell": "2.3.3",
"grunt-contrib-clean": "2.0.0", "grunt-contrib-clean": "2.0.0",

View File

@ -1,27 +1,35 @@
const should = require('should'); const chai = require('chai');
const {expect} = require('chai');
const {any, stringMatching} = require('expect');
const chaiJestSnapshot = require('@ethanresnick/chai-jest-snapshot');
const framework = require('../../../../utils/e2e-framework'); const framework = require('../../../../utils/e2e-framework');
const testUtils = require('../../../../utils');
const localUtils = require('./utils');
const config = require('../../../../../core/shared/config'); const config = require('../../../../../core/shared/config');
chai.use(chaiJestSnapshot);
describe('Config API', function () { describe('Config API', function () {
let request; let request;
before(async function () { before(async function () {
chaiJestSnapshot.resetSnapshotRegistry();
request = await framework.getAgent('/ghost/api/canary/admin/'); request = await framework.getAgent('/ghost/api/canary/admin/');
}); });
beforeEach(function () {
chaiJestSnapshot.configureUsingMochaContext(this);
});
it('can retrieve config and all expected properties', async function () { it('can retrieve config and all expected properties', async function () {
const res = await request const res = await request
.get('site/') .get('site/')
.set('Origin', config.get('url')) .set('Origin', config.get('url'));
.expect('Content-Type', /json/)
.expect('Cache-Control', testUtils.cacheRules.private)
.expect(200);
localUtils.API.checkResponse(res.body.site, 'site'); expect(res.body.site).to.matchSnapshot({
version: stringMatching(/\d+\.\d+/)
// minor (safe) version });
res.body.site.version.should.match(/\d+\.\d+/); expect(res.headers).to.matchSnapshot({
date: any(String),
etag: any(String)
});
}); });
}); });

View File

@ -0,0 +1,27 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`Config API can retrieve config and all expected properties 1`] = `
Object {
"accent_color": "#FF1A75",
"description": "Thoughts, stories and ideas",
"icon": null,
"logo": null,
"title": "Ghost",
"url": "http://127.0.0.1:2369/",
"version": StringMatching /\\\\d\\+\\\\\\.\\\\d\\+/,
}
`;
exports[`Config API can retrieve config and all expected properties 2`] = `
Object {
"access-control-allow-origin": "http://127.0.0.1:2369",
"cache-control": "no-cache, private, no-store, must-revalidate, max-stale=0, post-check=0, pre-check=0",
"connection": "close",
"content-length": "167",
"content-type": "application/json; charset=utf-8",
"date": Any<String>,
"etag": Any<String>,
"vary": "Origin, Accept-Encoding",
"x-powered-by": "Express",
}
`;

4300
yarn.lock

File diff suppressed because it is too large Load Diff