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

Unit test #17

Merged
merged 15 commits into from
Dec 15, 2023
Merged
Show file tree
Hide file tree
Changes from 12 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
34 changes: 34 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: CI

on:
pull_request:

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: 'lts/*'

- name: Install pnpm
run: npm install -g pnpm

- name: Install dependencies
run: pnpm install

- name: Lint
run: pnpm lint

- name: Typecheck
run: pnpm check-ts

- name: Build
run: pnpm run build

- name: Test
run: pnpm run test
3 changes: 3 additions & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
presets: [['@babel/preset-env', { targets: { node: 'current' } }], '@babel/preset-typescript'],
}
8 changes: 2 additions & 6 deletions dist/createRspackDevServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const makeRspackConfig_1 = require("./makeRspackConfig");
const debug = (0, debug_1.default)('cypress:rspack-dev-server:start');
async function createRspackDevServer(config) {
var _a;
const { sourceRspackModulesResult: { rspack: { module: rspack }, rspackDevServer: { majorVersion: rspackDevServerMajorVersion }, }, } = config;
const { sourceRspackModulesResult: { rspack: { module: rspack }, }, } = config;
const finalRspackConfig = await (0, makeRspackConfig_1.makeRspackConfig)(config);
const rspackCompiler = rspack(finalRspackConfig, undefined);
const { devServerConfig: { cypressConfig: { devServerPublicPathRoute }, }, } = config;
Expand All @@ -22,10 +22,6 @@ async function createRspackDevServer(config) {
overlay: false,
} });
const server = new RspackDevServer(rspackDevServerConfig, rspackCompiler);
return {
server,
compiler: rspackCompiler,
};
throw new Error(`Unsupported rspackDevServer version ${rspackDevServerMajorVersion}`);
return { server, compiler: rspackCompiler };
}
exports.createRspackDevServer = createRspackDevServer;
1 change: 0 additions & 1 deletion dist/devServer.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ export declare namespace devServer {
var create: (devServerConfig: DevServerConfig) => Promise<{
server: RspackDevServer;
compiler: any;
version: 0;
}>;
}
export type PresetHandlerResult = {
Expand Down
1 change: 0 additions & 1 deletion dist/devServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ devServer.create = async function (devServerConfig) {
const result = {
server,
compiler,
version: sourceRspackModulesResult.rspackDevServer.majorVersion,
};
return result;
};
Expand Down
2 changes: 0 additions & 2 deletions dist/helpers/sourceRelativeRspackModules.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,11 @@ export interface SourcedDependency {
}
export interface SourcedRspack extends SourcedDependency {
module: Function;
majorVersion: 0;
}
export interface SourcedRspackDevServer extends SourcedDependency {
module: {
new (...args: unknown[]): RspackDevServer;
};
majorVersion: 0;
}
export interface SourceRelativeRspackResult {
framework: SourcedDependency | null;
Expand Down
2 changes: 0 additions & 2 deletions dist/helpers/sourceRelativeRspackModules.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ function sourceRspack(config, framework) {
rspack.importPath = path_1.default.dirname(rspackJsonPath);
rspack.packageJson = require(rspackJsonPath);
rspack.module = require(rspack.importPath).rspack;
rspack.majorVersion = getMajorVersion(rspack.packageJson, [0]);
debug('Rspack: Successfully sourced rspack - %o', rspack);
module_1.default._load = function (request, parent, isMain) {
if (request === 'rspack' || request.startsWith('rspack/')) {
Expand Down Expand Up @@ -135,7 +134,6 @@ function sourceRspackDevServer(config, framework) {
rspackDevServer.importPath = path_1.default.dirname(rspackDevServerJsonPath);
rspackDevServer.packageJson = require(rspackDevServerJsonPath);
rspackDevServer.module = require(rspackDevServer.importPath).RspackDevServer;
rspackDevServer.majorVersion = getMajorVersion(rspackDevServer.packageJson, [0]);
debug('RspackDevServer: Successfully sourced rspack-dev-server - %o', rspackDevServer);
return rspackDevServer;
}
Expand Down
5 changes: 2 additions & 3 deletions dist/makeDefaultRspackConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const OUTPUT_PATH = path_1.default.join(__dirname, 'dist');
const OsSeparatorRE = RegExp(`\\${path_1.default.sep}`, 'g');
const posixSeparator = '/';
function makeCypressRspackConfig(config) {
const { devServerConfig: { cypressConfig: { projectRoot, devServerPublicPathRoute, supportFile, indexHtmlFile, isTextTerminal: isRunMode, }, specs: files, devServerEvents, framework, }, sourceRspackModulesResult: { rspack: { module: rspack }, }, } = config;
const { devServerConfig: { cypressConfig: { projectRoot, devServerPublicPathRoute, supportFile, indexHtmlFile, isTextTerminal: isRunMode, }, specs: files, devServerEvents, }, sourceRspackModulesResult: { rspack: { module: rspack }, }, } = config;
const optimization = {
// To prevent files from being tree shaken by rspack, we set optimization.sideEffects: false ensuring that
// rspack does not recognize the sideEffects flag in the package.json and thus files are not unintentionally
Expand Down Expand Up @@ -56,7 +56,6 @@ function makeCypressRspackConfig(config) {
ignored: '**/*',
};
}
// @ts-ignore
return Object.assign({}, finalConfig);
return finalConfig;
}
exports.makeCypressRspackConfig = makeCypressRspackConfig;
15 changes: 11 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@
"scripts": {
"build": "pnpm tsc --skipLibCheck || echo 'built, with type errors'",
"build-prod": "pnpm build",
"check-ts": "tsc --noEmit",
"check-ts": "tsc --noEmit --skipLibCheck",
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'd add this to the tsconfig

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, moved

"dev": "DEBUG=cypress:rspack-dev-server:* tsc --watch",
"clean": "rimraf dist",
"cypress:run": "pnpm cypress:run-cypress-in-cypress node ../../scripts/cypress run --project . --browser chrome",
"cypress:run-cypress-in-cypress": "cross-env CYPRESS_INTERNAL_E2E_TESTING_SELF_PARENT_PROJECT=1 HTTP_PROXY_TARGET_FOR_ORIGIN_REQUESTS=http://localhost:4455 CYPRESS_REMOTE_DEBUGGING_PORT=6666 TZ=America/New_York",
"cypress:open": "pnpm cypress:run-cypress-in-cypress gulp open --project .",
"lint": "eslint ."
"lint": "eslint .",
"test": "jest"
},
"dependencies": {
"@rspack/cli": "^0.3.14",
Expand All @@ -22,24 +23,30 @@
"webpack-merge": "^5.10.0"
},
"devDependencies": {
"@babel/core": "^7.23.5",
"@babel/preset-env": "^7.23.5",
"@babel/preset-typescript": "^7.23.3",
"@jest/globals": "^29.7.0",
"@rspack/core": "^0.3.14",
"@rspack/dev-server": "^0.3.14",
"@types/debug": "^4.1.12",
"@types/fs-extra": "^11.0.1",
"@types/jest": "^29.5.10",
"@types/lodash": "^4.14.201",
"@types/proxyquire": "^1.3.28",
"@typescript-eslint/parser": "^6.11.0",
"@types/watchpack": "^2.4.4",
"@types/webpack-sources": "^3.2.3",
"@typescript-eslint/parser": "^6.11.0",
"babel-jest": "^29.7.0",
"cross-env": "^7.0.3",
"cypress": "^12.13.0",
"debug": "^4.3.4",
"dedent": "^0.7.0",
"eslint": "^8.54.0",
"eslint-config-prettier": "^9.0.0",
"fs-extra": "9.1.0",
"jest": "^29.7.0",
"lodash": "^4.17.21",
"mocha": "^9.2.2",
"path": "^0.12.7",
"prettier": "^3.1.0",
"proxyquire": "2.1.3",
Expand Down
Loading