Skip to content

Add unit tests #67

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

Merged
merged 3 commits into from
Sep 25, 2022
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
21 changes: 21 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Contribution Guidelines

## How to contribute

- Open a [GitHub Issue](https://github.com/geoffrich/svelte-adapter-azure-swa/issues) for a discussion of your idea before working on it
- Fork this repo, develop your solution and submit a PR

## What to contribute

See the [GitHub Issues](https://github.com/geoffrich/svelte-adapter-azure-swa/issues) list for any open Issue.

General improvements to any aspect of this adapter are welcome, just ensure major work is preceeded by a conversation in a [GitHub Issue](https://github.com/geoffrich/svelte-adapter-azure-swa/issues).

## Package scripts

- `npm run format`: format the code using Prettier
- `npm run format`: check that the code is correctly formated
- `npm run test`: run the unit tests using [Vitest](https://vitest.dev/)
- `npm run test:coverage`: check test coverage

_This was based on the contribution guidelines in [svelte-adapter-firebase](https://github.com/jthegedus/svelte-adapter-firebase/blob/main/CONTRIBUTING.md)_
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ export default {

An object containing additional [esbuild options](https://esbuild.github.io/api/#build-api). Currently only supports [external](https://esbuild.github.io/api/#external). If you require additional options to be exposed, plese [open an issue](https://github.com/geoffrich/svelte-adapter-azure-swa/issues).


```js
import azure from 'svelte-adapter-azure-swa';

Expand Down
73 changes: 42 additions & 31 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,43 +34,14 @@ export default function ({
name: 'adapter-azure-swa',

async adapt(builder) {
validateCustomConfig(customStaticWebAppConfig);

if (!customStaticWebAppConfig.routes) {
customStaticWebAppConfig.routes = [];
}

/** @type {import('./types/swa').StaticWebAppConfig} */
const swaConfig = {
...customStaticWebAppConfig,
routes: [
...customStaticWebAppConfig.routes,
{
route: '*',
methods: ['POST', 'PUT', 'DELETE'],
rewrite: ssrFunctionRoute
},
{
route: `/${builder.config.kit.appDir}/immutable/*`,
headers: {
'cache-control': 'public, immutable, max-age=31536000'
}
}
],
navigationFallback: {
rewrite: ssrFunctionRoute
},
platform: {
apiRuntime: 'node:16'
}
};

if (!existsSync(join('api', 'package.json'))) {
throw new Error(
'You need to create a package.json in your `api` directory. See the adapter README for details.'
);
}

const swaConfig = generateConfig(customStaticWebAppConfig, builder.config.kit.appDir);

const tmp = builder.getBuildDirectory('azure-tmp');
const publish = 'build';
const staticDir = join(publish, 'static');
Expand Down Expand Up @@ -143,3 +114,43 @@ export default function ({
}
};
}

/**
* @param {import('./types/swa').CustomStaticWebAppConfig} customStaticWebAppConfig
* @param {string} appDir
* @returns {import('./types/swa').StaticWebAppConfig}
*/
export function generateConfig(customStaticWebAppConfig, appDir) {
validateCustomConfig(customStaticWebAppConfig);

if (!customStaticWebAppConfig.routes) {
customStaticWebAppConfig.routes = [];
}

/** @type {import('./types/swa').StaticWebAppConfig} */
const swaConfig = {
...customStaticWebAppConfig,
routes: [
...customStaticWebAppConfig.routes,
{
route: '*',
methods: ['POST', 'PUT', 'DELETE'],
rewrite: ssrFunctionRoute
},
{
route: `/${appDir}/immutable/*`,
headers: {
'cache-control': 'public, immutable, max-age=31536000'
}
}
],
navigationFallback: {
rewrite: ssrFunctionRoute
},
platform: {
apiRuntime: 'node:16'
}
};

return swaConfig;
}
Loading