Skip to content

Commit

Permalink
feat(ssr): support ssr
Browse files Browse the repository at this point in the history
  • Loading branch information
JOU-amjs committed May 8, 2023
1 parent 3201a79 commit f5e0826
Show file tree
Hide file tree
Showing 20 changed files with 344 additions and 52 deletions.
File renamed without changes.
16 changes: 10 additions & 6 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ jobs:
# 拉取代码
- name: Checkout
uses: actions/checkout@v3
with:
persist-credentials: false
- name: Use Node.js
uses: actions/setup-node@v3
with:
Expand All @@ -35,16 +37,19 @@ jobs:

# 这条命令包含了测试
- name: Unit tests
if: ${{ github.ref != 'refs/heads/main' && github.ref != 'refs/heads/alpha' && github.ref != 'refs/heads/beta' }}
run: npm run test

release:
runs-on: ubuntu-latest
needs: [quality]
if: ${{ github.ref == 'refs/heads/main' }}
if: ${{ github.ref == 'refs/heads/main' || github.ref == 'refs/heads/alpha' || github.ref == 'refs/heads/beta' }}
steps:
# 拉取代码
- name: Checkout
uses: actions/checkout@v3
with:
persist-credentials: false
- name: Use Node.js
uses: actions/setup-node@v3
with:
Expand All @@ -56,16 +61,15 @@ jobs:
- name: Install deps
run: npm ci

- name: Test SSR
run: npm run test:node

# 这条命令包含了测试和上传覆盖率
- name: Coverage
run: npm run coveralls

# 打包发布
- name: Build
run: npm run build --if-present

- name: Release
run: npm run release
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_ALOVA_PUBLISH_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_TOKEN: ${{ secrets.ALOVA_GITHUB_TOKEN }}
File renamed without changes.
14 changes: 9 additions & 5 deletions .releaserc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@ branches:
prerelease: true

plugins:
- "@semantic-release/commit-analyzer"
- "@semantic-release/release-notes-generator"
- "@semantic-release/npm"
- "@semantic-release/github"
- "@semantic-release/git"
- '@semantic-release/commit-analyzer'
- '@semantic-release/release-notes-generator'
- '@semantic-release/npm'
- '@semantic-release/github'
- '@semantic-release/git'
- - '@semantic-release/exec'

# 使用下一个版本号执行打包命令
- prepareCmd: 'cross-env VERSION=${nextRelease.version} npm run build'
12 changes: 0 additions & 12 deletions babel.config.js

This file was deleted.

File renamed without changes.
9 changes: 5 additions & 4 deletions config/rollup.js → config/rollup.cjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* @Date: 2020-04-09 11:06:01
* @LastEditors: JOU(wx: huzhen555)
* @LastEditTime: 2022-11-30 21:15:34
* @LastEditTime: 2023-05-08 23:00:03
*/
var typescript = require('rollup-plugin-typescript2');
var { readFileSync } = require('fs');
Expand All @@ -19,11 +19,12 @@ const getCompiler = (
) => typescript(opt);
exports.getCompiler = getCompiler;

const pkg = JSON.parse(readFileSync('package.json').toString() || '{}');
const { version, author, homepage } = pkg;
const pkg = require('../package.json');
const version = process.env.VERSION || pkg.version;
const author = pkg.author;
const repository = pkg.repository.url.replace('git', 'https').replace('.git', '');
exports.banner = `/**
* ${pkg.name} ${version} (${homepage})
* ${pkg.name} ${version} (${pkg.homepage})
* Copyright ${new Date().getFullYear()} ${author}. All Rights Reserved
* Licensed under MIT (${repository}/blob/master/LICENSE)
*/
Expand Down
2 changes: 1 addition & 1 deletion config/rollup.config.js → config/rollup.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/
// rollup.config.js
// commonjs
var config = require('./rollup.js');
var config = require('./rollup.cjs');
var module = process.argv.pop().replace('--', '') || 'core';
var paths = config.compilePath;
var moduleType = 'cjs';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// rollup.config.js
// ES output
var { nodeResolve } = require('@rollup/plugin-node-resolve');
var config = require('./rollup.js');
var config = require('./rollup.cjs');
var paths = config.compilePath;
var moduleType = 'esm';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ var commonjs = require('@rollup/plugin-commonjs');
var { terser } = require('rollup-plugin-terser');
var replace = require('@rollup/plugin-replace');
var json = require('@rollup/plugin-json');
var config = require('./rollup.js');
var config = require('./rollup.cjs');
var prod = process.env.NODE_ENV === 'production';
var paths = config.compilePath;
var moduleType = prod ? 'umd.min' : 'umd';
Expand Down
209 changes: 209 additions & 0 deletions jest.config.node.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,209 @@
/*
* For a detailed explanation regarding each configuration property and type check, visit:
* https://jestjs.io/docs/configuration
*/

export default {
// All imported modules in your tests should be mocked automatically
// automock: false,

// Stop running tests after `n` failures
// bail: 0,

// The directory where Jest should store its cached dependency information
// cacheDirectory: "C:\\Users\\Administrator\\AppData\\Local\\Temp\\jest",

// Automatically clear mock calls, instances, contexts and results before every test
// clearMocks: false,

// Indicates whether the coverage information should be collected while executing the test
collectCoverage: false,

// An array of glob patterns indicating a set of files for which coverage information should be collected
// collectCoverageFrom: undefined,

// The directory where Jest should output its coverage files
coverageDirectory: 'coverage',

// An array of regexp pattern strings used to skip coverage collection
coveragePathIgnorePatterns: ['\\\\node_modules\\\\', '/node_modules/', 'test/utils.ts'],

// Indicates which provider should be used to instrument code for coverage
coverageProvider: 'v8',

// A list of reporter names that Jest uses when writing coverage reports
coverageReporters: ['json', 'text', 'lcov', 'clover'],

// An object that configures minimum threshold enforcement for coverage results
// coverageThreshold: undefined,

// A path to a custom dependency extractor
// dependencyExtractor: undefined,

// Make calling deprecated APIs throw helpful error messages
// errorOnDeprecated: false,

// The default configuration for fake timers
// fakeTimers: {
// "enableGlobally": false
// },

// Force coverage collection from ignored files using an array of glob patterns
// forceCoverageMatch: [],

// A path to a module which exports an async function that is triggered once before all test suites
// globalSetup: undefined,

// A path to a module which exports an async function that is triggered once after all test suites
// globalTeardown: undefined,

// A set of global variables that need to be available in all test environments
// globals: {},

// The maximum amount of workers used to run your tests. Can be specified as % or a number. E.g. maxWorkers: 10% will use 10% of your CPU amount + 1 as the maximum worker number. maxWorkers: 2 will use a maximum of 2 workers.
// maxWorkers: "50%",

// An array of directory names to be searched recursively up from the requiring module's location
// moduleDirectories: ['<rootDir>/node_modules', 'node_modules'],

// An array of file extensions your modules use
moduleFileExtensions: [
'js',
// "mjs",
// "cjs",
'jsx',
'ts',
'tsx',
'json',
'node',
'svelte'
],

// A map from regular expressions to module names or to arrays of module names that allow to stub out resources with a single module
moduleNameMapper: {
// must use absolute paths
},

// An array of regexp pattern strings, matched against all module paths before considered 'visible' to the module loader
// modulePathIgnorePatterns: [],

// Activates notifications for test results
// notify: false,

// An enum that specifies notification mode. Requires { notify: true }
// notifyMode: "failure-change",

// A preset that is used as a base for Jest's configuration
// preset: 'ts-jest/presets/js-with-ts',

// Run tests from one or more projects
// projects: undefined,

// Use this configuration option to add custom reporters to Jest
// reporters: undefined,

// Automatically reset mock state before every test
// resetMocks: false,

// Reset the module registry before running each individual test
// resetModules: false,

// A path to a custom resolver
// resolver: undefined,

// Automatically restore mock state and implementation before every test
// restoreMocks: false,

// The root directory that Jest should scan for tests and modules within
// rootDir: undefined,

// A list of paths to directories that Jest should use to search for files in
// roots: [
// "<rootDir>"
// ],

// Allows you to use a custom runner instead of Jest's default test runner
// runner: "jest-runner",

// The paths to modules that run some code to configure or set up the testing environment before each test
// setupFiles: [],

// A list of paths to modules that run some code to configure or set up the testing framework before each test
setupFilesAfterEnv: ['<rootDir>/test/setup.ts'],

// The number of seconds after which a test is considered as slow and reported as such in the results.
// slowTestThreshold: 5,

// A list of paths to snapshot serializer modules Jest should use for snapshot testing
// snapshotSerializers: [],

// The test environment that will be used for testing
// testEnvironment: 'node',

testMatch: [
'**/?(*.)+(spec|test).[tj]s?(x)'
// '**/test/requestAdapter.spec.ts(x)?'
// '**/test/mockResponse.spec.ts(x)?'
],

// An array of regexp pattern strings that are matched against all test paths, matched tests are skipped
testPathIgnorePatterns: [
'\\\\node_modules\\\\', // windows
'/node_modules/' // mac
],

// The regexp pattern or array of patterns that Jest uses to detect test files
// testRegex: [],

// This option allows the use of a custom results processor
// testResultsProcessor: undefined,

// This option allows use of a custom test runner
// testRunner: "jest-circus/runner",

// A map from regular expressions to paths to transformers
transform: {
'\\.(j|t)sx?$': [
'ts-jest',
// mock import.meta, see https://www.npmjs.com/package/ts-jest-mock-import-meta
{
diagnostics: {
ignoreCodes: [1343]
},
astTransformers: {
// 转换import.meta
before: [
{
path: 'node_modules/ts-jest-mock-import-meta',
options: {
metaObjectReplacement: {
url: 'https://xxx',
env: {
PROD: false,
DEV: true
},
status: 2
}
}
}
]
}
}
]
},

// An array of regexp pattern strings that are matched against all source file paths, matched files will skip transformation
transformIgnorePatterns: ['/node_modules/(?!alova)']

// An array of regexp pattern strings that are matched against all modules before the module loader will automatically return a mock for them
// unmockedModulePathPatterns: undefined,

// Indicates whether each individual test should be reported during the run
// verbose: undefined,

// An array of regexp patterns that are matched against all source file paths before re-running tests in watch mode
// watchPathIgnorePatterns: [],

// Whether to use watchman for file crawling
// watchman: true,
};
4 changes: 2 additions & 2 deletions jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,10 @@ export default {
// runner: "jest-runner",

// The paths to modules that run some code to configure or set up the testing environment before each test
// setupFiles: ['<rootDir>/test/server.ts'],
// setupFiles: [],

// A list of paths to modules that run some code to configure or set up the testing framework before each test
// setupFilesAfterEnv: [],
setupFilesAfterEnv: ['<rootDir>/test/setup.ts'],

// The number of seconds after which a test is considered as slow and reported as such in the results.
// slowTestThreshold: 5,
Expand Down
Loading

0 comments on commit f5e0826

Please sign in to comment.