[next] remove tests already migrated to next-server

This commit is contained in:
Resi Respati
2019-02-20 11:20:33 +07:00
parent 02ba783ed3
commit 1c072e7caf
8 changed files with 1 additions and 281 deletions
-7
View File
@@ -1,7 +0,0 @@
import * as React from "react";
interface Props {
foo: string;
}
export const MyComponent: React.SFC<Props> = ({ foo: text }) => <span>{text}</span>;
-11
View File
@@ -1,11 +0,0 @@
import * as React from "react";
interface Props {
foo: boolean;
}
export default class MyComponent extends React.Component<Props> {
render() {
return this.props.foo ? <div/> : null;
}
}
-30
View File
@@ -1,30 +0,0 @@
import {
PHASE_DEVELOPMENT_SERVER,
IS_BUNDLED_PAGE_REGEX
} from "next/constants";
const isIndexPage = IS_BUNDLED_PAGE_REGEX.test(
"static/CjW0mFnyG80HdP4eSUiy7/pages/index.js"
);
// Example taken from: https://github.com/cyrilwanner/next-compose-plugins/blob/a25b313899638912cc9defc0be072f4fe4a1e855/README.md
const config = (nextConfig: any = {}) => {
return {
...nextConfig,
// define in which phases this plugin should get applied.
// you can also use multiple phases or negate them.
// however, users can still overwrite them in their configuration if they really want to.
phases: [PHASE_DEVELOPMENT_SERVER],
webpack(config: any, options: any) {
// do something here which only gets applied during development server phase
if (typeof nextConfig.webpack === "function") {
return nextConfig.webpack(config, options);
}
return config;
}
};
};
-81
View File
@@ -1,81 +0,0 @@
import * as React from "react";
import dynamic, { LoadingComponentProps } from "next/dynamic";
// You'd typically do this via import('./MyComponent')
interface MyComponentProps {
foo: string;
}
const MyComponent: React.StatelessComponent<MyComponentProps> = () => <div>I'm async!</div>;
const asyncComponent = Promise.resolve(MyComponent);
// Examples from
// https://github.com/zeit/next.js/#dynamic-import
const LoadingComponent: React.StatelessComponent<LoadingComponentProps> = ({
isLoading,
error
}) => <p>loading...</p>;
// 1. Basic Usage (Also does SSR)
const DynamicComponent = dynamic(Promise.resolve(MyComponent));
const dynamicComponentJSX = <DynamicComponent foo="bar" />;
// 1.1 Basic Usage (Loader function, module shape with 'export = Component' / 'module.exports = Component')
const DynamicComponent2 = dynamic(() => Promise.resolve(MyComponent));
const dynamicComponent2JSX = <DynamicComponent2 foo="bar" />;
// 1.2 Basic Usage (Loader function, module shape with 'export default Component')
const DynamicComponent3 = dynamic(() => Promise.resolve({ default: MyComponent }));
const dynamicComponent3JSX = <DynamicComponent3 foo="bar" />;
// TODO: Work with module shape 'export { Component }'
// 2. With Custom Loading Component
const DynamicComponentWithCustomLoading = dynamic(import('./imports/with-default'), {
loading: LoadingComponent
});
const dynamicComponentWithCustomLoadingJSX = <DynamicComponentWithCustomLoading foo />;
// 2.1. With Custom Loading Component (() => import('') syntax)
const DynamicComponentWithCustomLoading2 = dynamic(() => import('./imports/with-default'), {
loading: LoadingComponent
});
const dynamicComponentWithCustomLoading2JSX = <DynamicComponentWithCustomLoading2 foo />;
// 3. With No SSR
const DynamicComponentWithNoSSR = dynamic(() => import('./imports/with-default'), {
ssr: false
});
// 4. With Multiple Modules At Once
const HelloBundle = dynamic<MyComponentProps>({
modules: () => {
const components = {
Hello1: () => import('./imports/with-default'),
Hello2: () => import('./imports/with-default')
};
return components;
},
render: (props, { Hello1, Hello2 }) => (
<div>
<h1>{props.foo}</h1>
<Hello1 />
<Hello2 />
</div>
)
});
const helloBundleJSX = <HelloBundle foo="bar" />;
// 5. With plain Loadable options
const LoadableComponent = dynamic({
loader: () => import('./imports/with-default'),
loading: LoadingComponent,
delay: 200,
timeout: 10000
});
// 6. No loading
const DynamicComponentWithNoLoading = dynamic(asyncComponent, {
loading: () => null
});
-11
View File
@@ -1,11 +0,0 @@
import Head, * as head from "next/head";
import * as React from "react";
const elements: JSX.Element[] = head.defaultHead();
const jsx = <Head>{elements}</Head>;
if (!Head.canUseDOM) {
Head.rewind().map(x => [x.key, x.props, x.type]);
}
Head.peek().map(x => [x.key, x.props, x.type]);
-23
View File
@@ -1,23 +0,0 @@
import Link from "next/link";
import * as React from "react";
const links = (
<div>
<Link
as="foo"
href="https://www.example.com"
onError={(e: any) => {
console.log("Handled error!", e);
}}
prefetch
replace
scroll
shallow
>
<a>Gotta link to somewhere!</a>
</Link>
<Link>
<a>All props are optional!</a>
</Link>
</div>
);
-110
View File
@@ -1,110 +0,0 @@
import Router, { withRouter, WithRouterProps } from "next/router";
import * as React from "react";
import * as qs from "querystring";
Router.readyCallbacks.push(() => {
console.log("I'll get called when the router initializes.");
});
Router.ready(() => {
console.log(
"I'll get called immediately if the router initializes, or when it eventually does.",
);
});
// Access readonly properties of the router.
Object.keys(Router.components).forEach(key => {
const c = Router.components[key];
c.err.isAnAny;
return <c.Component />;
});
function split(routeLike: string) {
routeLike.split("/").forEach(part => {
console.log("path part: ", part);
});
}
if (Router.asPath) {
split(Router.asPath);
split(Router.asPath);
}
split(Router.pathname);
const query = `?${qs.stringify(Router.query)}`;
// Assign some callback methods.
Router.events.on('routeChangeStart', (url: string) => console.log("Route is starting to change.", url));
Router.events.on('beforeHistoryChange', (as: string) => console.log("History hasn't changed yet.", as));
Router.events.on('routeChangeComplete', (url: string) => console.log("Route change is complete.", url));
Router.events.on('routeChangeError', (err: any, url: string) => console.log("Route change errored.", err, url));
// Call methods on the router itself.
Router.reload("/route").then(() => console.log("route was reloaded"));
Router.back();
Router.beforePopState(({ url }) => !!url);
Router.push("/route").then((success: boolean) =>
console.log("route push success: ", success),
);
Router.push("/route", "/asRoute").then((success: boolean) =>
console.log("route push success: ", success),
);
Router.push("/route", "/asRoute", { shallow: false }).then((success: boolean) =>
console.log("route push success: ", success),
);
Router.replace("/route").then((success: boolean) =>
console.log("route replace success: ", success),
);
Router.replace("/route", "/asRoute").then((success: boolean) =>
console.log("route replace success: ", success),
);
Router.replace("/route", "/asRoute", {
shallow: false,
}).then((success: boolean) => console.log("route replace success: ", success));
Router.prefetch("/route").then(Component => {
const element = <Component />;
});
interface TestComponentProps {
testValue: string;
}
class TestComponent extends React.Component<TestComponentProps & WithRouterProps> {
state = { ready: false };
constructor(props: TestComponentProps & WithRouterProps) {
super(props);
if (props.router) {
props.router.ready(() => {
this.setState({ ready: true });
});
}
}
render() {
return (
<div>
<h1>{this.state.ready ? 'Ready' : 'Not Ready'}</h1>
<h2>Route: {this.props.router ? this.props.router.route : ""}</h2>
<p>Another prop: {this.props.testValue}</p>
</div>
);
}
}
withRouter(TestComponent);
interface TestFCQuery {
test?: string;
}
interface TestFCProps extends WithRouterProps<TestFCQuery> { }
const TestFC: React.FunctionComponent<TestFCProps> = ({ router }) => {
return <div>{router && router.query && router.query.test}</div>;
};
+1 -8
View File
@@ -30,16 +30,9 @@
"router.d.ts",
"config.d.ts",
"test/next-tests.ts",
"test/next-constants-tests.ts",
"test/next-app-tests.tsx",
"test/next-error-tests.tsx",
"test/next-head-tests.tsx",
"test/next-document-tests.tsx",
"test/next-link-tests.tsx",
"test/next-dynamic-tests.tsx",
"test/next-router-tests.tsx",
"test/next-component-tests.tsx",
"test/imports/no-default.tsx",
"test/imports/with-default.tsx"
"test/next-component-tests.tsx"
]
}