Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor tests for readability #51051

Merged
merged 4 commits into from Jun 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -169,6 +169,7 @@
"npm-run-all": "4.1.5",
"nprogress": "0.2.0",
"open": "9.0.0",
"outdent": "0.8.0",
"pixrem": "5.0.0",
"playwright-chromium": "1.28.1",
"plop": "3.0.5",
Expand Down
6 changes: 6 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

47 changes: 21 additions & 26 deletions test/development/acceptance-app/ReactRefresh.test.ts
@@ -1,29 +1,24 @@
/* eslint-env jest */
import { sandbox } from './helpers'
import { createNext, FileRef } from 'e2e-utils'
import { NextInstance } from 'test/lib/next-modes/base'
import { sandbox } from 'development-sandbox'
import { FileRef, nextTestSetup } from 'e2e-utils'
import path from 'path'
import { outdent } from 'outdent'

describe('ReactRefresh app', () => {
let next: NextInstance

beforeAll(async () => {
next = await createNext({
files: new FileRef(path.join(__dirname, 'fixtures', 'default-template')),
dependencies: {
react: 'latest',
'react-dom': 'latest',
},
skipStart: true,
})
const { next } = nextTestSetup({
files: new FileRef(path.join(__dirname, 'fixtures', 'default-template')),
dependencies: {
react: 'latest',
'react-dom': 'latest',
},
skipStart: true,
})
afterAll(() => next.destroy())

test('can edit a component without losing state', async () => {
const { session, cleanup } = await sandbox(next)
await session.patch(
'index.js',
`
outdent`
import { useCallback, useState } from 'react'
export default function Index() {
const [count, setCount] = useState(0)
Expand All @@ -43,7 +38,7 @@ describe('ReactRefresh app', () => {
).toBe('1')
await session.patch(
'index.js',
`
outdent`
import { useCallback, useState } from 'react'
export default function Index() {
const [count, setCount] = useState(0)
Expand Down Expand Up @@ -72,7 +67,7 @@ describe('ReactRefresh app', () => {

await session.write(
'NudgeOverview.js',
`
outdent`
import * as React from 'react';

import { foo } from './routes';
Expand All @@ -88,7 +83,7 @@ describe('ReactRefresh app', () => {

await session.write(
'SurveyOverview.js',
`
outdent`
const SurveyOverview = () => {
return 100;
};
Expand All @@ -99,7 +94,7 @@ describe('ReactRefresh app', () => {

await session.write(
'Milestones.js',
`
outdent`
import React from 'react';

import { fragment } from './DashboardPage';
Expand All @@ -115,7 +110,7 @@ describe('ReactRefresh app', () => {

await session.write(
'DashboardPage.js',
`
outdent`
import React from 'react';

import Milestones from './Milestones';
Expand All @@ -140,7 +135,7 @@ describe('ReactRefresh app', () => {

await session.write(
'routes.js',
`
outdent`
import DashboardPage from './DashboardPage';

export const foo = {};
Expand All @@ -154,7 +149,7 @@ describe('ReactRefresh app', () => {

await session.patch(
'index.js',
`
outdent`
import * as React from 'react';

import DashboardPage from './routes';
Expand All @@ -173,7 +168,7 @@ describe('ReactRefresh app', () => {

let didFullRefresh = !(await session.patch(
'SurveyOverview.js',
`
outdent`
const SurveyOverview = () => {
return 200;
};
Expand All @@ -189,7 +184,7 @@ describe('ReactRefresh app', () => {

didFullRefresh = !(await session.patch(
'index.js',
`
outdent`
import * as React from 'react';

import DashboardPage from './routes';
Expand All @@ -209,7 +204,7 @@ describe('ReactRefresh app', () => {

didFullRefresh = !(await session.patch(
'SurveyOverview.js',
`
outdent`
const SurveyOverview = () => {
return 300;
};
Expand Down