Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions tests/src/Application.njs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ import Vunerability from './Vunerability';
import WindowDependency from './WindowDependency';
import WorkerVerbs from './WorkerVerbs';
import MetatagState from './MetatagState';
import TypeScriptExtension from './TypeScriptExtension';
import JavaScriptExtension from './JavaScriptExtension';

class Application extends Nullstack {

Expand Down Expand Up @@ -111,6 +113,8 @@ class Application extends Nullstack {
<ComponentTernary route="/component-ternary" />
<AnchorModifiers route="/anchor-modifiers" />
<MetatagState route="/metatag-state" />
<JavaScriptExtension route="/javascript-extension" />
<TypeScriptExtension route="/typescript-extension" generic />
<ErrorPage route="*" />
</main>
)
Expand Down
15 changes: 15 additions & 0 deletions tests/src/JavaScriptExtension.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import Nullstack from 'nullstack';

class JavaScriptExtension extends Nullstack {

render({ environment }) {
return (
<div data-imported >
{environment.key}
</div>
)
}

}

export default JavaScriptExtension;
13 changes: 13 additions & 0 deletions tests/src/JavaScriptExtension.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
beforeAll(async () => {
await page.goto('http://localhost:6969/javascript-extension');
});

describe('JavaScriptExtension', () => {

test('components can use the jsx extension', async () => {
await page.waitForSelector('[data-imported]');
const element = await page.$('[data-imported]');
expect(element).toBeTruthy();
});

});
21 changes: 21 additions & 0 deletions tests/src/TypeScriptExtension.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import Nullstack from 'nullstack';
import { NullstackClientContext } from 'nullstack/types';

interface TypeScriptExtensionProps {
generic: boolean
route?: string
}

class TypeScriptExtension extends Nullstack<TypeScriptExtensionProps> {

render({ generic, environment }: NullstackClientContext & TypeScriptExtensionProps) {
return (
<div data-imported data-generic={generic}>
{environment.key}
</div>
)
}

}

export default TypeScriptExtension;
19 changes: 19 additions & 0 deletions tests/src/TypesScriptExtension.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
beforeAll(async () => {
await page.goto('http://localhost:6969/typescript-extension');
});

describe('TypeScriptExtension', () => {

test('components can use the tsx extension', async () => {
await page.waitForSelector('[data-generic]');
const element = await page.$('[data-generic]');
expect(element).toBeTruthy();
});

test('class components accept generics', async () => {
await page.waitForSelector('[data-generic]');
const element = await page.$('[data-generic]');
expect(element).toBeTruthy();
});

});
3 changes: 2 additions & 1 deletion types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ export * from './ServerContext'
export * from './Settings'
export * from './Worker'

export default class Nullstack {
export default class Nullstack<Type = any> {
constructor(props?: Type)
static start?(App: any): NullstackClientContext | NullstackServerContext
static use?(Plugin: NullstackPlugin)
}
28 changes: 14 additions & 14 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function cacheFactory(args, folder, name) {
const babel = {
test: /\.js$/,
resolve: {
extensions: ['.njs', '.js', '.nts', '.ts']
extensions: ['.njs', '.js', '.nts', '.ts', '.tsx', '.jsx']
},
use: {
loader: require.resolve('babel-loader'),
Expand All @@ -39,9 +39,9 @@ const babel = {
};

const nullstackJavascript = {
test: /\.(njs|nts)$/,
test: /\.(njs|nts|jsx|tsx)$/,
resolve: {
extensions: ['.njs', '.js', '.nts', '.ts']
extensions: ['.njs', '.js', '.nts', '.ts', '.tsx', '.jsx']
},
use: {
loader: require.resolve('babel-loader'),
Expand All @@ -64,9 +64,9 @@ const nullstackJavascript = {
};

const nullstackTypescript = {
test: /\.nts$/,
test: /\.(nts|tsx)$/,
resolve: {
extensions: ['.njs', '.js', '.nts', '.ts']
extensions: ['.njs', '.js', '.nts', '.ts', '.tsx', '.jsx']
},
use: {
loader: require.resolve('babel-loader'),
Expand Down Expand Up @@ -163,11 +163,11 @@ function server(env, argv) {
babel,
nullstackJavascript,
{
test: /.(njs|nts)$/,
test: /\.(njs|nts|jsx|tsx)$/,
loader: path.resolve('./node_modules/nullstack/loaders/inject-nullstack.js'),
},
{
test: /.(njs|nts)$/,
test: /\.(njs|nts|jsx|tsx)$/,
loader: path.resolve('./node_modules/nullstack/loaders/register-static-from-server.js'),
},
{
Expand All @@ -178,11 +178,11 @@ function server(env, argv) {
},
nullstackTypescript,
{
test: /.(njs|nts)$/,
test: /\.(njs|nts|jsx|tsx)$/,
loader: path.resolve('./node_modules/nullstack/loaders/add-source-to-node.js'),
},
{
test: /.(njs|nts)$/,
test: /\.(njs|nts|jsx|tsx)$/,
loader: path.resolve('./node_modules/nullstack/loaders/register-inner-components.js'),
},
]
Expand Down Expand Up @@ -251,15 +251,15 @@ function client(env, argv) {
babel,
nullstackJavascript,
{
test: /.(njs|nts)$/,
test: /\.(njs|nts|jsx|tsx)$/,
loader: path.resolve('./node_modules/nullstack/loaders/remove-import-from-client.js'),
},
{
test: /.(njs|nts)$/,
test: /\.(njs|nts|jsx|tsx)$/,
loader: path.resolve('./node_modules/nullstack/loaders/inject-nullstack.js'),
},
{
test: /.(njs|nts)$/,
test: /\.(njs|nts|jsx|tsx)$/,
loader: path.resolve('./node_modules/nullstack/loaders/remove-static-from-client.js'),
},
{
Expand All @@ -273,11 +273,11 @@ function client(env, argv) {
liveReload,
nullstackTypescript,
{
test: /.(njs|nts)$/,
test: /\.(njs|nts|jsx|tsx)$/,
loader: path.resolve('./node_modules/nullstack/loaders/add-source-to-node.js'),
},
{
test: /.(njs|nts)$/,
test: /\.(njs|nts|jsx|tsx)$/,
loader: path.resolve('./node_modules/nullstack/loaders/register-inner-components.js'),
},
]
Expand Down