Skip to content

Commit

Permalink
Add new files and configurations for base app
Browse files Browse the repository at this point in the history
  • Loading branch information
serifcolakel committed Feb 10, 2024
1 parent 539e78c commit d5f0a01
Show file tree
Hide file tree
Showing 39 changed files with 1,417 additions and 5 deletions.
3 changes: 1 addition & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,5 @@
"activityBar.background": "#2B3106",
"titleBar.activeBackground": "#3C4408",
"titleBar.activeForeground": "#F9FCE5"
},
"editor.formatOnSave": true
}
}
10 changes: 10 additions & 0 deletions apps/base-e2e/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": ["plugin:cypress/recommended", "../../.eslintrc.json"],
"ignorePatterns": ["!**/*"],
"overrides": [
{
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
"rules": {}
}
]
}
17 changes: 17 additions & 0 deletions apps/base-e2e/cypress.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
import { nxE2EPreset } from '@nx/cypress/plugins/cypress-preset';
import { defineConfig } from 'cypress';

export default defineConfig({
e2e: {
...nxE2EPreset(__filename, {
cypressDir: 'src',
webServerCommands: {
default: 'nx run base:serve',
production: 'nx run base:preview',
},
ciWebServerCommand: 'nx run base:serve-static',
}),
baseUrl: 'http://localhost:4200',
},
});
9 changes: 9 additions & 0 deletions apps/base-e2e/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "base-e2e",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"projectType": "application",
"sourceRoot": "apps/base-e2e/src",
"targets": {},
"implicitDependencies": ["base"],
"tags": []
}
13 changes: 13 additions & 0 deletions apps/base-e2e/src/e2e/app.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { getGreeting } from '../support/app.po';

describe('base-e2e', () => {
beforeEach(() => cy.visit('/'));

it('should display welcome message', () => {
// Custom command example, see `../support/commands.ts` file
cy.login('[email protected]', 'myPassword');

// Function helper example, see `../support/app.po.ts` file
getGreeting().contains(/Welcome/);
});
});
5 changes: 5 additions & 0 deletions apps/base-e2e/src/fixtures/example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "Using fixtures to represent data",
"email": "[email protected]",
"body": "Fixtures are a great way to mock data for responses to routes"
}
1 change: 1 addition & 0 deletions apps/base-e2e/src/support/app.po.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const getGreeting = () => cy.get('h1');
35 changes: 35 additions & 0 deletions apps/base-e2e/src/support/commands.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// / <reference types="cypress" />

// ***********************************************
// This example commands.ts shows you how to
// create various custom commands and overwrite
// existing commands.
//
// For more comprehensive examples of custom
// commands please read more here:
// https://on.cypress.io/custom-commands
// ***********************************************

// eslint-disable-next-line @typescript-eslint/no-namespace
declare namespace Cypress {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
interface Chainable<Subject> {
login(email: string, password: string): void;
}
}

// -- This is a parent command --
Cypress.Commands.add('login', (email, password) => {
window.console.log('Custom command example: Login', email, password);
});
//
// -- This is a child command --
// Cypress.Commands.add("drag", { prevSubject: 'element'}, (subject, options) => { ... })
//
//
// -- This is a dual command --
// Cypress.Commands.add("dismiss", { prevSubject: 'optional'}, (subject, options) => { ... })
//
//
// -- This will overwrite an existing command --
// Cypress.Commands.overwrite("visit", (originalFn, url, options) => { ... })
17 changes: 17 additions & 0 deletions apps/base-e2e/src/support/e2e.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// ***********************************************************
// This example support/e2e.ts is processed and
// loaded automatically before your test files.
//
// This is a great place to put global configuration and
// behavior that modifies Cypress.
//
// You can change the location of this file or turn off
// automatically serving support files with the
// 'supportFile' configuration option.
//
// You can read more here:
// https://on.cypress.io/configuration
// ***********************************************************

// Import commands.ts using ES2015 syntax:
import './commands';
20 changes: 20 additions & 0 deletions apps/base-e2e/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"allowJs": true,
"outDir": "../../dist/out-tsc",
"module": "commonjs",
"types": ["cypress", "node"],
"sourceMap": false
},
"include": [
"**/*.ts",
"**/*.js",
"cypress.config.ts",
"**/*.cy.ts",
"**/*.cy.tsx",
"**/*.cy.js",
"**/*.cy.jsx",
"**/*.d.ts"
]
}
11 changes: 11 additions & 0 deletions apps/base/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"presets": [
[
"@nx/react/babel",
{
"runtime": "automatic"
}
]
],
"plugins": []
}
18 changes: 18 additions & 0 deletions apps/base/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"extends": ["plugin:@nx/react", "../../.eslintrc.json"],
"ignorePatterns": ["!**/*"],
"overrides": [
{
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
"rules": {}
},
{
"files": ["*.ts", "*.tsx"],
"rules": {}
},
{
"files": ["*.js", "*.jsx"],
"rules": {}
}
]
}
11 changes: 11 additions & 0 deletions apps/base/jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/* eslint-disable */
export default {
displayName: 'base',
preset: '../../jest.preset.js',
transform: {
'^(?!.*\\.(js|jsx|ts|tsx|css|json)$)': '@nx/react/plugins/jest',
'^.+\\.[tj]sx?$': ['babel-jest', { presets: ['@nx/react/babel'] }],
},
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx'],
coverageDirectory: '../../coverage/apps/base',
};
11 changes: 11 additions & 0 deletions apps/base/module-federation.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { ModuleFederationConfig } from '@nx/webpack';

const config: ModuleFederationConfig = {
name: 'base',

exposes: {
'./Test': './src/app/Test.tsx',
},
};

export default config;
88 changes: 88 additions & 0 deletions apps/base/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
{
"name": "base",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "apps/base/src",
"projectType": "application",
"targets": {
"build": {
"executor": "@nx/webpack:webpack",
"outputs": ["{options.outputPath}"],
"defaultConfiguration": "production",
"options": {
"compiler": "babel",
"outputPath": "dist/apps/base",
"index": "apps/base/src/index.html",
"baseHref": "/",
"main": "apps/base/src/main.ts",
"tsConfig": "apps/base/tsconfig.app.json",
"assets": ["apps/base/src/favicon.ico", "apps/base/src/assets"],
"styles": ["apps/base/src/styles.css"],
"scripts": [],
"webpackConfig": "apps/base/webpack.config.ts"
},

"configurations": {
"development": {
"extractLicenses": false,
"optimization": false,
"sourceMap": true,
"vendorChunk": true
},
"production": {
"fileReplacements": [
{
"replace": "apps/base/src/environments/environment.ts",
"with": "apps/base/src/environments/environment.prod.ts"
}
],
"crossOrigin": "anonymous",
"optimization": true,
"outputHashing": "all",
"sourceMap": false,
"namedChunks": false,
"extractLicenses": true,
"vendorChunk": false,
"webpackConfig": "apps/base/webpack.config.prod.ts"
}
}
},
"serve": {
"executor": "@nx/webpack:dev-server",
"defaultConfiguration": "development",
"options": {
"buildTarget": "base:build",
"hmr": true,
"allowedHosts": "all",
"port": 3003
},
"configurations": {
"development": {
"buildTarget": "base:build:development"
},
"production": {
"allowedHosts": "all",
"buildTarget": "base:build:production",
"hmr": false
}
}
},
"serve-static": {
"executor": "@nx/web:file-server",
"defaultConfiguration": "production",
"options": {
"buildTarget": "base:build",
"watch": false,
"port": 3003
},
"configurations": {
"development": {
"buildTarget": "base:build:development"
},
"production": {
"buildTarget": "base:build:production"
}
}
}
},
"tags": []
}
33 changes: 33 additions & 0 deletions apps/base/src/app/Test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { useEffect, useState } from 'react';

export default function Test() {
const [ test, setTest ] = useState(0);
const [ todos, setTodos ] = useState<{ userId: number, id: number, title: string, completed: boolean }[]>([]);

const getTodos = async () => {
const response = await fetch('https://jsonplaceholder.typicode.com/todos');
const data = await response.json() as { userId: number, id: number, title: string, completed: boolean }[];

setTodos(data);
};

useEffect(() => {
getTodos();
}, []);

return (
<div>
<h1>Test From Base Module</h1>
<button onClick={() => setTest((oldTest) => oldTest + 1)}>Click me {test}</button>
<div>
<h2>Todo List</h2>

<ul>
{todos.map((todo) => (
<li key={todo.id}>{todo.title}</li>
))}
</ul>
</div>
</div>
);
}
1 change: 1 addition & 0 deletions apps/base/src/app/app.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/* Your styles goes here. */
18 changes: 18 additions & 0 deletions apps/base/src/app/app.spec.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/* eslint-disable @typescript-eslint/no-unsafe-call */
import { render } from '@testing-library/react';

import App from './app';

describe('App', () => {
it('should render successfully', () => {
const { baseElement } = render(<App />);

expect(baseElement).toBeTruthy();
});

it('should have a greeting as the title', () => {
const { getByText } = render(<App />);

expect(getByText(/Welcome base/gi)).toBeTruthy();
});
});
11 changes: 11 additions & 0 deletions apps/base/src/app/app.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import NxWelcome from './nx-welcome';

export function App() {
return (
<div>
<NxWelcome title="base" />
</div>
);
}

export default App;
Loading

0 comments on commit d5f0a01

Please sign in to comment.