diff --git a/.changeset/chilly-snails-tease.md b/.changeset/chilly-snails-tease.md new file mode 100644 index 000000000..a845151cc --- /dev/null +++ b/.changeset/chilly-snails-tease.md @@ -0,0 +1,2 @@ +--- +--- diff --git a/.github/integ-config/local-integ-all.yml b/.github/integ-config/local-integ-all.yml new file mode 100644 index 000000000..9710753f5 --- /dev/null +++ b/.github/integ-config/local-integ-all.yml @@ -0,0 +1,4 @@ +tests: + - test_name: webpack_e2e_test + desc: 'Webpack 5' + framework: webpack \ No newline at end of file diff --git a/.github/workflows/callable-local-e2e-test.yml b/.github/workflows/callable-local-e2e-test.yml new file mode 100644 index 000000000..d8f9883b2 --- /dev/null +++ b/.github/workflows/callable-local-e2e-test.yml @@ -0,0 +1,45 @@ +name: E2E Test +run-name: e2e.${{ inputs.test_name }} + +on: + workflow_call: + inputs: + test_name: + required: true + type: string + framework: + required: true + type: string + timeout_minutes: + required: true + type: number + +jobs: + e2e-test: + name: E2E ${{ inputs.test_name }} + runs-on: ubuntu-latest + timeout-minutes: ${{ inputs.timeout_minutes }} + + steps: + - name: Checkout repository + uses: actions/checkout@24cb9080177205b6e8c946b17badbe402adc938f # v3.4.0 https://github.com/actions/checkout/commit/24cb9080177205b6e8c946b17badbe402adc938f + with: + path: amplify-data + - name: Setup node and build the repository + uses: ./amplify-data/.github/actions/node-and-build + - name: Run e2e tests for ${{ inputs.test_name }} dev + shell: bash + working-directory: ./amplify-data + env: + E2E_FRAMEWORK: ${{ inputs.framework }} + E2E_TEST_NAME: ${{ inputs.test_name }} + run: | + npm run ci:test dev + - name: Run e2e tests for ${{ inputs.test_name }} prod + shell: bash + working-directory: ./amplify-data + env: + E2E_FRAMEWORK: ${{ inputs.framework }} + E2E_TEST_NAME: ${{ inputs.test_name }} + run: | + npm run ci:test prod \ No newline at end of file diff --git a/.github/workflows/callable-local-e2e-tests.yml b/.github/workflows/callable-local-e2e-tests.yml index 0d9d94e2f..8d11a1810 100644 --- a/.github/workflows/callable-local-e2e-tests.yml +++ b/.github/workflows/callable-local-e2e-tests.yml @@ -26,3 +26,34 @@ jobs: - name: Run tests working-directory: ./amplify-data run: npm run e2e-node:test + + e2e-prep: + name: Get local E2E test config + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 + with: + path: amplify-data + - name: Read integ config files + id: load_config + run: | + echo "INTEG_CONFIG=$(cat .github/integ-config/local-integ-all.yml | yq '.tests' -o=json | jq -c .)" >> $GITHUB_OUTPUT + working-directory: ./amplify-data + outputs: + integ-config: ${{ steps.load_config.outputs.INTEG_CONFIG }} + + + e2e-test-runner: + name: E2E test runnner + needs: e2e-prep + secrets: inherit + strategy: + matrix: + integ-config: ${{ fromJson(needs.e2e-prep.outputs.integ-config) }} + fail-fast: false + uses: ./.github/workflows/callable-local-e2e-test.yml + with: + test_name: ${{ matrix.integ-config.test_name }} + framework: ${{ matrix.integ-config.framework }} + timeout_minutes: ${{ matrix.integ-config.timeout_minutes || 35 }} diff --git a/e2e-TEST-COVERAGE.md b/e2e-TEST-COVERAGE.md index 3cd36cc64..9aafeff06 100644 --- a/e2e-TEST-COVERAGE.md +++ b/e2e-TEST-COVERAGE.md @@ -6,7 +6,7 @@ The following table outlines the current e2e test coverage for various runtimes |---------------------|-----------| | Chrome | [✅](.github/workflows/callable-e2e-test.yml) | | Node | [✅](packages/e2e-tests/node/jest.config.ts) | -| Webpack | ⚠️ | +| Webpack | [✅](packages/e2e-tests/webpack/webpack.config.js) | | Rollup | ⚠️ | | Metro | ⚠️ | | React Natives | ⚠️ | diff --git a/package-lock.json b/package-lock.json index 7f19bfa70..2b79c367f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -371,6 +371,25 @@ "node": ">=14" } }, + "node_modules/@ardatan/sync-fetch/node_modules/node-fetch": { + "version": "2.7.0", + "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.7.0.tgz", + "integrity": "sha512-c4FRfUm/dbcWZ7U+1Wq0AwCyFL+3nt2bEw05wfxSz+DWpWsitgmSgYmy2dQdWyKC1694ELPqMs/YzUSNozLt8A==", + "dependencies": { + "whatwg-url": "^5.0.0" + }, + "engines": { + "node": "4.x || >=6.0.0" + }, + "peerDependencies": { + "encoding": "^0.1.0" + }, + "peerDependenciesMeta": { + "encoding": { + "optional": true + } + } + }, "node_modules/@arktype/attest": { "version": "0.7.3", "resolved": "https://registry.npmjs.org/@arktype/attest/-/attest-0.7.3.tgz", @@ -10071,6 +10090,25 @@ "node-fetch": "^2.6.12" } }, + "node_modules/cross-fetch/node_modules/node-fetch": { + "version": "2.7.0", + "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.7.0.tgz", + "integrity": "sha512-c4FRfUm/dbcWZ7U+1Wq0AwCyFL+3nt2bEw05wfxSz+DWpWsitgmSgYmy2dQdWyKC1694ELPqMs/YzUSNozLt8A==", + "dependencies": { + "whatwg-url": "^5.0.0" + }, + "engines": { + "node": "4.x || >=6.0.0" + }, + "peerDependencies": { + "encoding": "^0.1.0" + }, + "peerDependenciesMeta": { + "encoding": { + "optional": true + } + } + }, "node_modules/cross-inspect": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/cross-inspect/-/cross-inspect-1.0.0.tgz", @@ -10129,6 +10167,15 @@ "node": ">=0.10" } }, + "node_modules/data-uri-to-buffer": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/data-uri-to-buffer/-/data-uri-to-buffer-4.0.1.tgz", + "integrity": "sha512-0R9ikRb668HB7QDxT1vkpuUBtqc53YyAwMwGeUFKRojY/NWKvdZ+9UYtRfGmhqNbRkTSVpMbmyhXipFFv2cb/A==", + "dev": true, + "engines": { + "node": ">= 12" + } + }, "node_modules/data-urls": { "version": "5.0.0", "resolved": "https://registry.npmjs.org/data-urls/-/data-urls-5.0.0.tgz", @@ -11686,6 +11733,29 @@ "integrity": "sha512-b2XGFAFdWZWg0phtAWLHCk836A1Xann+I+Dgd3Gk64MHKZO44FfoD1KxyvbSh0qZsIoXQGGlVztIY+oitJPpRQ==", "license": "MIT" }, + "node_modules/fetch-blob": { + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/fetch-blob/-/fetch-blob-3.2.0.tgz", + "integrity": "sha512-7yAQpD2UMJzLi1Dqv7qFYnPbaPx7ZfFK6PiIxQ4PfkGPyNyl2Ugx+a/umUonmKqjhM4DnfbMvdX6otXq83soQQ==", + "dev": true, + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/jimmywarting" + }, + { + "type": "paypal", + "url": "https://paypal.me/jimmywarting" + } + ], + "dependencies": { + "node-domexception": "^1.0.0", + "web-streams-polyfill": "^3.0.3" + }, + "engines": { + "node": "^12.20 || >= 14.13" + } + }, "node_modules/figures": { "version": "6.1.0", "resolved": "https://registry.npmjs.org/figures/-/figures-6.1.0.tgz", @@ -11883,6 +11953,18 @@ "node": ">= 6" } }, + "node_modules/formdata-polyfill": { + "version": "4.0.10", + "resolved": "https://registry.npmjs.org/formdata-polyfill/-/formdata-polyfill-4.0.10.tgz", + "integrity": "sha512-buewHzMvYL29jdeQTVILecSaZKnt/RJWjoZCF5OW60Z67/GmSLBkOFM7qh1PI3zFNtJbaZL5eQu1vLfazOwj4g==", + "dev": true, + "dependencies": { + "fetch-blob": "^3.1.2" + }, + "engines": { + "node": ">=12.20.0" + } + }, "node_modules/forwarded": { "version": "0.2.0", "resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.2.0.tgz", @@ -15733,23 +15815,41 @@ "tslib": "^2.0.3" } }, + "node_modules/node-domexception": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/node-domexception/-/node-domexception-1.0.0.tgz", + "integrity": "sha512-/jKZoMpw0F8GRwl4/eLROPA3cfcXtLApP0QzLmUT/HuPCZWyB7IY9ZrMeKw2O/nFIqPQB3PVM9aYm0F312AXDQ==", + "dev": true, + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/jimmywarting" + }, + { + "type": "github", + "url": "https://paypal.me/jimmywarting" + } + ], + "engines": { + "node": ">=10.5.0" + } + }, "node_modules/node-fetch": { - "version": "2.7.0", - "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.7.0.tgz", - "integrity": "sha512-c4FRfUm/dbcWZ7U+1Wq0AwCyFL+3nt2bEw05wfxSz+DWpWsitgmSgYmy2dQdWyKC1694ELPqMs/YzUSNozLt8A==", + "version": "3.3.2", + "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-3.3.2.tgz", + "integrity": "sha512-dRB78srN/l6gqWulah9SrxeYnxeddIG30+GOqK/9OlLVyLg3HPnr6SqOWTWOXKRwC2eGYCkZ59NNuSgvSrpgOA==", + "dev": true, "dependencies": { - "whatwg-url": "^5.0.0" + "data-uri-to-buffer": "^4.0.0", + "fetch-blob": "^3.1.4", + "formdata-polyfill": "^4.0.10" }, "engines": { - "node": "4.x || >=6.0.0" - }, - "peerDependencies": { - "encoding": "^0.1.0" + "node": "^12.20.0 || ^14.13.1 || >=16.0.0" }, - "peerDependenciesMeta": { - "encoding": { - "optional": true - } + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/node-fetch" } }, "node_modules/node-int64": { @@ -18968,6 +19068,15 @@ "makeerror": "1.0.12" } }, + "node_modules/web-streams-polyfill": { + "version": "3.3.3", + "resolved": "https://registry.npmjs.org/web-streams-polyfill/-/web-streams-polyfill-3.3.3.tgz", + "integrity": "sha512-d2JWLCivmZYTSIoge9MsgFCZrt571BikcWGYkjC1khllbTeDlGqZ2D8vD8E/lJa8WGWbb7Plm8/XJYV7IJHZZw==", + "dev": true, + "engines": { + "node": ">= 8" + } + }, "node_modules/webidl-conversions": { "version": "3.0.1", "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-3.0.1.tgz", diff --git a/package.json b/package.json index 4e52e0d0c..c3adafeac 100644 --- a/package.json +++ b/package.json @@ -44,6 +44,7 @@ "stop:npm-proxy": "tsx scripts/stop_npm_proxy.ts", "test": "turbo run test && npm run test:scripts && npm run e2e-exports", "test:scripts": "npx jest scripts/", + "ci:test": "./scripts/bundler_test.sh", "turbo": "turbo", "vend": "npm run start:npm-proxy && npm run publish:local" }, diff --git a/packages/e2e-tests/README.md b/packages/e2e-tests/README.md index 0783f8e13..d2019de99 100644 --- a/packages/e2e-tests/README.md +++ b/packages/e2e-tests/README.md @@ -1,8 +1,10 @@ # `amplify-data` E2E Tests +## Node testing + This package contains automated tests for validating functionality E2E in Node. -## How it works: +### How it works: - All tests within `node` share a single "long-lived" Amplify backend (added to the shared Cypress account). @@ -10,7 +12,7 @@ This package contains automated tests for validating functionality E2E in Node. - See [test utils](node/utils.ts) for helpers that configure Amplify, generate / configure the API client, as well as for additional test utilities and types. -## How to add a new test / test local changes: +### How to add a new test / test local changes: 1. Create a new file under `__tests__` 2. Use the helpers to configure Amplify and generate / configure the API client. @@ -19,12 +21,12 @@ This package contains automated tests for validating functionality E2E in Node. ensure that a `package-lock` file is not generated for this sample. 4. [TODO] subscription testing (will be added with follow-up PR) -## [TODO] Global cleanup +### [TODO] Global cleanup Add a check to clean up potential orphaned records after all tests have run (see https://jestjs.io/docs/configuration#globalteardown-string). -## [Known Issue] Jest open handles warning +### [Known Issue] Jest open handles warning Tests that use `Hub` currently emit the following warning when running the tests: @@ -42,7 +44,7 @@ TODO: Investigate and/or fix. All tests within the `sandbox` directory deploy a new sandbox for each test run. -## How it works: +### How it works: CLI commands are managed by the process controller. The process controller is responsible for executing CLI commands, and listening for output from the CLI. @@ -58,7 +60,7 @@ Test setup / execution is structured as follows: 5. Sandbox is torn down after the tests are complete. `.amplify/` and `amplify_outputs.json` are deleted. -## CI AWS Credentials: +### CI AWS Credentials: We follow the recommended OS approach to get AWS account credentials: https://w.amazon.com/bin/view/Open_Source/GitHub/Actions. Specifically, we use the [aws-actions/configure-aws-credentials](https://github.com/aws-actions/configure-aws-credentials#assuming-a-role) GH Action to obtain credentials from @@ -83,16 +85,27 @@ To view identify provider details in the console, see: `Console > IAM > Identity - https://docs.github.com/en/actions/deployment/security-hardening-your-deployments/configuring-openid-connect-in-amazon-web-services - https://github.com/aws-actions/configure-aws-credentials -## How to add a new test: +### How to add a new test: 1. Add a new project directory under `amplify-backends`. Must also contain a basic `package.json`. 2. Add a corresponding test file under `__tests__`. 3. Use the utils to generate / teardown the sandbox withthe process controller. -## Using Execa with Jest +### Using Execa with Jest Execa is the primary dependency used to run CLI commands in the process controller, and it is a pure ES module. Unlike `amplify-backend`, which uses the Node test runner, our tests are written in Jest. This results in [this issue](https://github.com/sindresorhus/execa/issues/465). The workaround is to use Jest's [experimental support for ECMAScript Modules](https://jestjs.io/docs/ecmascript-modules). There is a backlog item to investigate other potential solutions. + +## General tool testing: + +This is the general guidance for testing module bundlers. When testing other tools in the future, please adapt these guidelines accordingly and update this file. + +### How to add a new e2e test sample: + +1. Add a sample in this directory following the structure `e2e-tests/`. +2. Add configs for your test to the [local-integ-all.yml](../../.github/integ-config/local-integ-all.yml) file. +3. Create an npm command for your test script and call it from [callable-local-e2e-test](../../.github/workflows/callable-local-e2e-test.yml). +4. Update the e2e test coverage for `amplify-data` repo in [e2e test coverage table](../../e2e-TEST-COVERAGE.md). \ No newline at end of file diff --git a/packages/e2e-tests/webpack/.gitignore b/packages/e2e-tests/webpack/.gitignore new file mode 100644 index 000000000..399e09fe3 --- /dev/null +++ b/packages/e2e-tests/webpack/.gitignore @@ -0,0 +1,8 @@ +# amplify +node_modules +.amplify +amplify_outputs* +amplifyconfiguration* + +# lock file +package-lock.json \ No newline at end of file diff --git a/packages/e2e-tests/webpack/amplify/auth/resource.ts b/packages/e2e-tests/webpack/amplify/auth/resource.ts new file mode 100644 index 000000000..14a8886cd --- /dev/null +++ b/packages/e2e-tests/webpack/amplify/auth/resource.ts @@ -0,0 +1,11 @@ +import { defineAuth } from '@aws-amplify/backend'; + +/** + * Define and configure your auth resource + * @see https://docs.amplify.aws/gen2/build-a-backend/auth + */ +export const auth = defineAuth({ + loginWith: { + email: true, + }, +}); diff --git a/packages/e2e-tests/webpack/amplify/backend.ts b/packages/e2e-tests/webpack/amplify/backend.ts new file mode 100644 index 000000000..b793ab7c3 --- /dev/null +++ b/packages/e2e-tests/webpack/amplify/backend.ts @@ -0,0 +1,11 @@ +import { defineBackend } from '@aws-amplify/backend'; +import { auth } from './auth/resource'; +import { data } from './data/resource'; + +/** + * @see https://docs.amplify.aws/react/build-a-backend/ to add storage, functions, and more + */ +defineBackend({ + auth, + data, +}); diff --git a/packages/e2e-tests/webpack/amplify/data/resource.ts b/packages/e2e-tests/webpack/amplify/data/resource.ts new file mode 100644 index 000000000..90703862d --- /dev/null +++ b/packages/e2e-tests/webpack/amplify/data/resource.ts @@ -0,0 +1,53 @@ +import { type ClientSchema, a, defineData } from '@aws-amplify/backend'; + +/*== STEP 1 =============================================================== +The section below creates a Todo database table with a "content" field. Try +adding a new "isDone" field as a boolean. The authorization rule below +specifies that any unauthenticated user can "create", "read", "update", +and "delete" any "Todo" records. +=========================================================================*/ +const schema = a.schema({ + Todo: a + .model({ + content: a.string(), + }) + .authorization((allow) => [allow.guest()]), +}); + +export type Schema = ClientSchema; + +export const data = defineData({ + schema, + authorizationModes: { + defaultAuthorizationMode: 'iam', + }, +}); + +/*== STEP 2 =============================================================== +Go to your frontend source code. From your client-side code, generate a +Data client to make CRUDL requests to your table. (THIS SNIPPET WILL ONLY +WORK IN THE FRONTEND CODE FILE.) + +Using JavaScript or Next.js React Server Components, Middleware, Server +Actions or Pages Router? Review how to generate Data clients for those use +cases: https://docs.amplify.aws/gen2/build-a-backend/data/connect-to-API/ +=========================================================================*/ + +/* +"use client" +import { generateClient } from "aws-amplify/data"; +import type { Schema } from "@/amplify/data/resource"; + +const client = generateClient() // use this Data client for CRUDL requests +*/ + +/*== STEP 3 =============================================================== +Fetch records from the database and use them in your frontend component. +(THIS SNIPPET WILL ONLY WORK IN THE FRONTEND CODE FILE.) +=========================================================================*/ + +/* For example, in a React component, you can use this snippet in your + function's RETURN statement */ +// const { data: todos } = await client.models.Todo.list() + +// return
    {todos.map(todo =>
  • {todo.content}
  • )}
diff --git a/packages/e2e-tests/webpack/amplify/package.json b/packages/e2e-tests/webpack/amplify/package.json new file mode 100644 index 000000000..aead43de3 --- /dev/null +++ b/packages/e2e-tests/webpack/amplify/package.json @@ -0,0 +1,3 @@ +{ + "type": "module" +} \ No newline at end of file diff --git a/packages/e2e-tests/webpack/amplify/tsconfig.json b/packages/e2e-tests/webpack/amplify/tsconfig.json new file mode 100644 index 000000000..4eb4ab26c --- /dev/null +++ b/packages/e2e-tests/webpack/amplify/tsconfig.json @@ -0,0 +1,17 @@ +{ + "compilerOptions": { + "target": "es2022", + "module": "es2022", + "moduleResolution": "bundler", + "resolveJsonModule": true, + "esModuleInterop": true, + "forceConsistentCasingInFileNames": true, + "strict": true, + "skipLibCheck": true, + "paths": { + "$amplify/*": [ + "../.amplify/generated/*" + ] + } + } +} \ No newline at end of file diff --git a/packages/e2e-tests/webpack/index.html b/packages/e2e-tests/webpack/index.html new file mode 100644 index 000000000..594f4ed40 --- /dev/null +++ b/packages/e2e-tests/webpack/index.html @@ -0,0 +1,9 @@ + + + +

Amplify TypeScript App

+ + + + + \ No newline at end of file diff --git a/packages/e2e-tests/webpack/package.json b/packages/e2e-tests/webpack/package.json new file mode 100644 index 000000000..498558ccc --- /dev/null +++ b/packages/e2e-tests/webpack/package.json @@ -0,0 +1,37 @@ +{ + "name": "webpack", + "version": "1.0.0", + "description": "", + "main": "index.js", + "scripts": { + "start": "webpack && webpack-dev-server --mode development", + "build": "webpack", + "install:no-lock": "npm i --no-package-lock", + "clean": "rm -rf node_modules package-lock.json", + "serve": "serve -s dist -l 3000" + }, + "keywords": [], + "author": "", + "license": "ISC", + "devDependencies": { + "@aws-amplify/backend": "^1.13.0", + "@aws-amplify/backend-cli": "^1.4.6", + "@aws-amplify/data-schema": "file:../../../packages/data-schema", + "@aws-amplify/data-schema-types": "file:../../../packages/data-schema-types", + "aws-cdk": "^2.175.1", + "aws-cdk-lib": "^2.175.1", + "constructs": "^10.4.2", + "copy-webpack-plugin": "^12.0.2", + "esbuild": "^0.24.2", + "serve": "^14.2.4", + "ts-loader": "^9.5.2", + "tsx": "^4.19.2", + "typescript": "^5.7.3", + "webpack": "^5.97.1", + "webpack-cli": "^6.0.1", + "webpack-dev-server": "^5.2.0" + }, + "dependencies": { + "aws-amplify": "^6.12.0" + } +} diff --git a/packages/e2e-tests/webpack/src/app.ts b/packages/e2e-tests/webpack/src/app.ts new file mode 100644 index 000000000..db6e1f0ce --- /dev/null +++ b/packages/e2e-tests/webpack/src/app.ts @@ -0,0 +1,4 @@ +import { generateClient } from 'aws-amplify/data'; +import { Schema } from '@/amplify/data/resource'; + +const client = generateClient(); \ No newline at end of file diff --git a/packages/e2e-tests/webpack/tsconfig.json b/packages/e2e-tests/webpack/tsconfig.json new file mode 100644 index 000000000..5c0cd2ef1 --- /dev/null +++ b/packages/e2e-tests/webpack/tsconfig.json @@ -0,0 +1,21 @@ +{ + "compilerOptions": { + "lib": ["dom", "es2019", "es2020"], + "target": "es2020", + "allowJs": false, + "skipLibCheck": true, + "strict": true, + "forceConsistentCasingInFileNames": true, + "incremental": true, + "esModuleInterop": true, + "resolveJsonModule": true, + "noErrorTruncation": true, + "module": "esnext", + "moduleResolution": "bundler", + "paths": { + "@/*": ["./*"] + } + }, + "exclude": ["node_modules"], + "include": ["src"] + } \ No newline at end of file diff --git a/packages/e2e-tests/webpack/webpack.config.js b/packages/e2e-tests/webpack/webpack.config.js new file mode 100644 index 000000000..3ea871b6a --- /dev/null +++ b/packages/e2e-tests/webpack/webpack.config.js @@ -0,0 +1,41 @@ +const CopyWebpackPlugin = require('copy-webpack-plugin'); +const path = require('path'); +const webpack = require('webpack'); + +module.exports = { + mode: 'development', + entry: './src/app.ts', + output: { + filename: '[name].bundle.js', + path: path.resolve(__dirname, 'dist'), + }, + module: { + rules: [ + { + test: /\.ts$/, + exclude: /node_modules/, + use: 'ts-loader', + }, + ], + }, + resolve: { + extensions: ['.tsx', '.ts', '.js'], + }, + devServer: { + client: { + overlay: true + }, + static: { + directory: './dist' + }, + hot: true, + port: 3000, + allowedHosts: 'all', + }, + plugins: [ + new CopyWebpackPlugin({ + patterns: ['index.html'], + }), + new webpack.HotModuleReplacementPlugin(), + ], +}; \ No newline at end of file diff --git a/scripts/bundler_test.sh b/scripts/bundler_test.sh new file mode 100755 index 000000000..2f4b679ef --- /dev/null +++ b/scripts/bundler_test.sh @@ -0,0 +1,64 @@ +#!/bin/bash + +# Global variables to store PIDs +NPM_PID="" + +# Get the input argument +ENV=$1 + +# Function to run dev environment +run_dev() { + echo "dev npm --prefix packages/e2e-tests/webpack install && npm --prefix packages/e2e-tests/webpack run start" + npm --prefix packages/e2e-tests/webpack install && npm --prefix packages/e2e-tests/webpack run start & + NPM_PID=$! +} + +# Function to run prod environment +run_prod() { + echo "npm --prefix packages/e2e-tests/webpack install && npm --prefix packages/e2e-tests/webpack run build && + npm --prefix packages/e2e-tests/webpack run serve" + + npm --prefix packages/e2e-tests/webpack install && + npm --prefix packages/e2e-tests/webpack run build && + npm --prefix packages/e2e-tests/webpack run serve & + NPM_PID=$! +} + +# Check the input and run the appropriate command +if [ "$ENV" = "dev" ]; then + run_dev +elif [ "$ENV" = "prod" ]; then + run_prod +else + echo "Invalid argument. Please use 'dev' or 'prod'." + exit 1 +fi + +# Function to check if the server is up +echo "curl -s -o /dev/null -w "%{http_code}" http://localhost:3000 | grep -q "200"" +check_server() { + for i in {1..30}; do + sleep 5 + if curl -s -o /dev/null -w "%{http_code}" http://localhost:3000 | grep -q "200"; then + return 0 + fi + done + return 1 +} + +# Wait for the server to start (with timeout) +if check_server; then + echo "Test pass!" + # Kill the npm process + kill $NPM_PID + timeout 10s wait $NPM_PID 2>/dev/null || kill -9 $NPM_PID + echo "Server process terminated." + exit 0 +else + echo "Error: Command failed with exit code 1." + # Kill the npm process + kill $NPM_PID + timeout 10s wait $NPM_PID 2>/dev/null || kill -9 $NPM_PID + echo "Server process terminated." + exit 1 +fi \ No newline at end of file