Skip to content
This repository has been archived by the owner on Sep 9, 2024. It is now read-only.

Commit

Permalink
feat: v4.0.0 (#1016)
Browse files Browse the repository at this point in the history
Co-authored-by: Denys Konovalov <[email protected]>
Co-authored-by: Mathieu COSYNS <[email protected]>
  • Loading branch information
3 people authored Jan 3, 2024
1 parent 682576f commit 799c7e6
Show file tree
Hide file tree
Showing 732 changed files with 48,463 additions and 10,872 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
packages/app/yarn.lock
packages/core/yarn.lock
packages/docs/yarn.lock
node-version: 16
node-version: 18

- name: Install
run: |
Expand All @@ -50,7 +50,7 @@ jobs:
packages/app/yarn.lock
packages/core/yarn.lock
packages/docs/yarn.lock
node-version: 16
node-version: 18

- name: Install
run: |
Expand All @@ -75,7 +75,7 @@ jobs:
packages/app/yarn.lock
packages/core/yarn.lock
packages/docs/yarn.lock
node-version: 16
node-version: 18

- name: Install
run: |
Expand Down Expand Up @@ -105,7 +105,7 @@ jobs:
packages/app/yarn.lock
packages/core/yarn.lock
packages/docs/yarn.lock
node-version: 16
node-version: 18

- name: Install
run: |
Expand Down
49 changes: 49 additions & 0 deletions .github/workflows/cypress.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: Cypress Tests

on:
workflow_dispatch:
push:
branches: ['main', 'next']
pull_request:
branches: ['main', 'next']

jobs:
cypress-run:
runs-on: ubuntu-latest

strategy:
fail-fast: false # https://github.com/cypress-io/github-action/issues/48
matrix:
containers: [1, 2] # Uses 2 parallel instances

steps:
- uses: actions/checkout@v3

- name: Setup Node
uses: actions/setup-node@v3
with:
cache: yarn
cache-dependency-path: |
yarn.lock
packages/app/yarn.lock
packages/core/yarn.lock
packages/docs/yarn.lock
node-version: 18

- name: Install
run: |
yarn install --frozen-lockfile
- name: Run Cypress Tests
uses: cypress-io/github-action@v6
with:
start: yarn dev
wait-on: 'http://localhost:8080'
record: true # Records to Cypress Cloud
parallel: true # Runs test in parallel using settings above
env:
# For recording and parallelization to work you must set your CYPRESS_RECORD_KEY
# in GitHub repo → Settings → Secrets → Actions
CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }}
# Creating a token https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token
GITHUB_TOKEN: ${{ secrets.CYPRESS_GITHUB_TOKEN }}
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,7 @@
/node_modules
*.log
.vscode
cypress/screenshots
cypress/downloads
.env
.temp
4 changes: 4 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
dist/
bin/
public/
.cache/
6 changes: 6 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"arrowParens": "avoid",
"trailingComma": "all",
"singleQuote": true,
"printWidth": 100
}
19 changes: 19 additions & 0 deletions cypress.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { defineConfig } from "cypress";
import setupNodeEvents from "./cypress/plugins";

export default defineConfig({
projectId: "wvw3x3",
retries: {
runMode: 2,
openMode: 0,
},
chromeWebSecurity: false,
e2e: {
video: false,
// We've imported your old cypress plugins here.
// You may want to clean this up later by importing these.
setupNodeEvents,
baseUrl: "http://localhost:8080",
specPattern: "cypress/e2e/*.spec.ts",
},
});
72 changes: 72 additions & 0 deletions cypress/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# Cypress Tests Guide

## Introduction

[Cypress](https://www.cypress.io/) is a JavaScript End to End Testing Framework that runs in the browser.

Cypress tests run with a [local version](../packages/core/dev-test) of the CMS.

During the setup of a spec file, the relevant `index.html` and `config.yml` are copied from `packages/core/dev-test/backends/<backend>` to `dev-test`.

Tests for the `test` backend use mock data generated in `dev-test/backends/test/index.html`.

Tests for the other backends use previously [recorded data](fixtures) and stub `fetch` [calls](support/commands.js#L52). See more about recording tests data [here](#recording-tests-data).

## Run Tests Locally

```bash
yarn test:e2e # builds the demo site and runs Cypress in headless mode with mock data
```

## Debug Tests

```bash
yarn develop # starts a local dev server with the demo site
yarn test:e2e:exec # runs Cypress in non-headless mode with mock data
```

## Recording Tests Data

When recording tests, access to the relevant backend API is required, thus one must set up a `.env` file in the root project directory in the following format:

```bash
GITHUB_REPO_OWNER=owner
GITHUB_REPO_NAME=repo
GITHUB_REPO_TOKEN=tokenWithWritePermissions
GITHUB_OPEN_AUTHORING_OWNER=forkOwner
GITHUB_OPEN_AUTHORING_TOKEN=tokenWithWritePermissions

GITLAB_REPO_OWNER=owner
GITLAB_REPO_NAME=repo
GITLAB_REPO_TOKEN=tokenWithWritePermissions

BITBUCKET_REPO_OWNER=owner
BITBUCKET_REPO_NAME=repo
BITBUCKET_OUATH_CONSUMER_KEY=ouathConsumerKey
BITBUCKET_OUATH_CONSUMER_SECRET=ouathConsumerSecret

NETLIFY_API_TOKEN=netlifyApiToken
NETLIFY_INSTALLATION_ID=netlifyGitHubInstallationId
```

> The structure of the relevant repo should match the settings in [`config.yml`](../packages/core/dev-test/backends/<backend>/config.yml#L1)
To start a recording run the following commands:

```bash
yarn develop # starts a local dev server with the demo site
yarn mock:server:start # starts the recording proxy
yarn test:e2e:record-fixtures:dev # runs Cypress in non-headless and pass data through the recording proxy
yarn mock:server:stop # stops the recording proxy
```

> During the recorded process a clone of the relevant repo will be created under `.temp` and reset between tests.
Recordings are sanitized from any possible sensitive data and [transformed](plugins/common.js#L34) into an easier to process format.

To avoid recording all the tests over and over again, a recommended process is to:

1. Mark the specific test as `only` by changing `it("some test...` to `it.only("some test...` for the relevant test.
2. Run the test in recording mode.
3. Exit Cypress and stop the proxy.
4. Run the test normally (with mock data) to verify the recording works.
82 changes: 82 additions & 0 deletions cypress/cypress.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/// <reference types="cypress" />

import type {
SetupBackendProps,
SetupBackendTestProps,
SeedRepoProps,
TeardownBackendTestProps,
TeardownBackendProps,
} from './interface';
import type { Config as CMSConfig, DeepPartial } from '@staticcms/core/interface';

interface KeyProps {
shift?: boolean;
times?: number;
}

declare global {
namespace Cypress {
interface Chainable {
task(event: 'setupBackend', props: SetupBackendProps): Chainable<SetupBackendResponse>;
task(event: 'setupBackendTest', props: SetupBackendTestProps): Chainable<Promise<null>>;
task(event: 'seedRepo', props: SeedRepoProps): Chainable<Promise<null>>;
task(event: 'teardownBackendTest', props: TeardownBackendTestProps): Chainable<Promise<null>>;
task(event: 'teardownBackend', props: TeardownBackendProps): Chainable<Promise<null>>;
task(event: 'updateConfig', props: DeepPartial<CMSConfig>): Chainable<Promise<null>>;

login(): Chainable;
loginAndNewPost(): Chainable;

dragTo(selector: string, options?: { delay?: number }): Chainable;

getMarkdownEditor(): Chainable;
confirmMarkdownEditorContent(expected: string): Chainable;
clearMarkdownEditorContent(): Chainable;
confirmRawEditorContent(expected: string): Chainable;

enter(props?: KeyProps): Chainable;
backspace(props?: KeyProps): Chainable;
selectAll(props?: KeyProps): Chainable;
up(props?: KeyProps): Chainable;
down(props?: KeyProps): Chainable;
left(props?: KeyProps): Chainable;
right(props?: KeyProps): Chainable;
tabkey(props?: KeyProps): Chainable;

selection(
fn: (this: Cypress.ObjectLike, currentSubject: JQuery<any>) => Chainable,
): Chainable;
setSelection(
query:
| string
| {
anchorQuery: string;
anchorOffset?: number;
focusQuery: string;
focusOffset?: number;
},
endQuery: string,
): Chainable;

setCursor(query: string, atStart?: boolean): Chainable;
setCursorBefore(query: string): Chainable;
setCursorAfter(query: string): Chainable;

print(message: string): Chainable;

insertCodeBlock(): Chainable;
insertEditorComponent(title: string): Chainable;

clickToolbarButton(title: string, opts: { times: number }): Chainable;
clickHeadingOneButton(opts: { times: number }): Chainable;
clickHeadingTwoButton(opts: { times: number }): Chainable;
clickOrderedListButton(opts: { times: number }): Chainable;
clickUnorderedListButton(opts: { times: number }): Chainable;
clickCodeButton(opts: { times: number }): Chainable;
clickItalicButton(opts: { times: number }): Chainable;
clickQuoteButton(opts: { times: number }): Chainable;
clickLinkButton(opts: { times: number }): Chainable;
clickModeToggle(): Chainable;
}
}
}
30 changes: 30 additions & 0 deletions cypress/e2e/_old/editorial_workflow_spec_bitbucket_backend.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import fixture from '../common/editorial_workflow';
import * as specUtils from '../common/spec_utils';
import { entry1, entry2, entry3 } from '../common/entries';

const backend = 'bitbucket';

describe('BitBucket Backend Editorial Workflow', () => {
let taskResult = { data: {} };

before(() => {
specUtils.before(taskResult, { publish_mode: 'editorial_workflow' }, backend);
});

after(() => {
specUtils.after(taskResult, backend);
});

beforeEach(() => {
specUtils.beforeEach(taskResult, backend);
});

afterEach(() => {
specUtils.afterEach(taskResult, backend);
});

fixture({
entries: [entry1, entry2, entry3],
getUser: () => taskResult.data.user,
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import fixture from '../common/editorial_workflow';
import * as specUtils from '../common/spec_utils';
import { entry1, entry2, entry3 } from '../common/entries';

const backend = 'git-gateway';
const provider = 'github';

describe('Git Gateway (GitHub) Backend Editorial Workflow', () => {
let taskResult = { data: {} };

before(() => {
specUtils.before(taskResult, { publish_mode: 'editorial_workflow', provider }, backend);
});

after(() => {
specUtils.after(taskResult, backend);
});

beforeEach(() => {
specUtils.beforeEach(taskResult, backend);
});

afterEach(() => {
specUtils.afterEach(taskResult, backend);
});

fixture({
entries: [entry1, entry2, entry3],
getUser: () => taskResult.data.user,
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import fixture from '../common/editorial_workflow';
import * as specUtils from '../common/spec_utils';
import { entry1, entry2, entry3 } from '../common/entries';

const backend = 'git-gateway';
const provider = 'gitlab';

describe('Git Gateway (GitLab) Backend Editorial Workflow', () => {
let taskResult = { data: {} };

before(() => {
specUtils.before(taskResult, { publish_mode: 'editorial_workflow', provider }, backend);
});

after(() => {
specUtils.after(taskResult, backend);
});

beforeEach(() => {
specUtils.beforeEach(taskResult, backend);
});

afterEach(() => {
specUtils.afterEach(taskResult, backend);
});

fixture({
entries: [entry1, entry2, entry3],
getUser: () => taskResult.data.user,
});
});
Loading

0 comments on commit 799c7e6

Please sign in to comment.