Skip to content

Commit

Permalink
Merge pull request #50 from sambauers/sambauers/typescript
Browse files Browse the repository at this point in the history
  • Loading branch information
UncleClapton committed Feb 25, 2023
2 parents e5cee58 + 2199c97 commit 91ba427
Show file tree
Hide file tree
Showing 38 changed files with 2,882 additions and 4,181 deletions.
25 changes: 8 additions & 17 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
name: Release



on:
workflow_run:
workflows:
Expand All @@ -20,29 +18,22 @@ jobs:
if: ${{ github.event.workflow_run.conclusion == 'success' }}
steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: Setup Node
uses: actions/setup-node@v2

- name: Locate Yarn Cache Directory
id: locate-yarn-cache
run: echo "::set-output name=dir::$(yarn cache dir)"

- name: Retrieve Yarn Cache
id: retrieve-yarn-cache
uses: actions/cache@v2
uses: actions/setup-node@v3
with:
path: ${{ steps.locate-yarn-cache.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
node-version-file: '.nvmrc'
cache: 'yarn'

- name: Install Packages
run: yarn install

- name: Build distribution
run: yarn build

- name: Release
run: npx semantic-release
run: yarn semantic-release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
18 changes: 4 additions & 14 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,13 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: Setup Node
uses: actions/setup-node@v2

- name: Locate Yarn Cache Directory
id: locate-yarn-cache
run: echo "::set-output name=dir::$(yarn cache dir)"

- name: Retrieve Yarn Cache
id: retrieve-yarn-cache
uses: actions/cache@v2
uses: actions/setup-node@v3
with:
path: ${{ steps.locate-yarn-cache.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
node-version-file: '.nvmrc'
cache: 'yarn'

- name: Install Packages
run: yarn install
Expand Down
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
lts/*
11 changes: 11 additions & 0 deletions .releaserc
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,16 @@
"name": "alpha",
"prerelease": true
}
],
"plugins": [
"@semantic-release/commit-analyzer",
"@semantic-release/release-notes-generator",
[
"@semantic-release/npm",
{
"pkgRoot": "dist"
}
],
"@semantic-release/github"
]
}
38 changes: 6 additions & 32 deletions __tests__/buildCSPHeaders.js → __tests__/buildCSPHeaders.ts
Original file line number Diff line number Diff line change
@@ -1,44 +1,18 @@
// Local imports
const buildCSPHeaders = require('../lib/buildCSPHeaders')





// Local constants
const DEFAULT_CSP = {
'base-uri': '\'none\'',
'child-src': '\'none\'',
'connect-src': '\'self\'',
'default-src': '\'self\'',
'font-src': '\'self\'',
'form-action': '\'self\'',
'frame-ancestors': '\'none\'',
'frame-src': '\'none\'',
'img-src': '\'self\'',
'manifest-src': '\'self\'',
'media-src': '\'self\'',
'object-src': '\'none\'',
'prefetch-src': '\'self\'',
'script-src': '\'self\'',
'style-src': '\'self\'',
'worker-src': '\'self\'',
}




import buildCSPHeaders from '../src/lib/buildCSPHeaders'
import { CSP_REQUIRED_DIRECTIVE_DEFAULTS } from '../src/models/CSP'
import type { NextSafeConfig } from '../src/models/nextSafe'

describe('buildCSPHeaders', () => {
function testCSPWithConfig(testName, config) {
function testCSPWithConfig(testName: string, config?: NextSafeConfig) {
test(testName, () => {
const builtCSPHeaders = buildCSPHeaders(config)
const expectedCSP = {
...DEFAULT_CSP,
...CSP_REQUIRED_DIRECTIVE_DEFAULTS,
...(config?.contentSecurityPolicy || {}),
}

if (config?.isDev) {
if (config?.isDev && config.contentSecurityPolicy !== false) {
if (!config.contentSecurityPolicy?.['connect-src']) {
expectedCSP['connect-src'] = '\'self\' webpack://*'
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const buildPermissionsPolicyHeaders = require('../lib/buildPermissionsPolicyHeaders')
// Local imports
import buildPermissionsPolicyHeaders from '../src/lib/buildPermissionsPolicyHeaders'

describe('buildPermissionsPolicyHeaders', () => {

test('with defaults', () => {
const result = buildPermissionsPolicyHeaders()

Expand Down Expand Up @@ -41,5 +41,4 @@ describe('buildPermissionsPolicyHeaders', () => {
]
)
})

})
44 changes: 44 additions & 0 deletions __tests__/crunchCSPHeaderValue.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Local imports
import crunchCSPHeaderValue from '../src/lib/crunchCSPHeaderValue'

describe('crunchCSPHeaderValue', () => {
test('with single header', () => {
const crunchedHeaders = crunchCSPHeaderValue({
'base-uri': 'header-value',
})

expect(crunchedHeaders).toEqual('base-uri header-value;')
})

test('with multiple headers', () => {
const crunchedHeaders = crunchCSPHeaderValue({
'base-uri': 'header-value1',
'child-src': 'header-value2',
})

expect(crunchedHeaders).toEqual('base-uri header-value1;child-src header-value2;')
})

test('with values array', () => {
const crunchedHeaders = crunchCSPHeaderValue({
'base-uri': [
'header-value1',
'header-value2',
],
})

expect(crunchedHeaders).toEqual('base-uri header-value1 header-value2;')
})

test('with mixed value types', () => {
const crunchedHeaders = crunchCSPHeaderValue({
'base-uri': 'header-value1',
'child-src': [
'header-value2',
'header-value3',
],
})

expect(crunchedHeaders).toEqual('base-uri header-value1;child-src header-value2 header-value3;')
})
})
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
// Local imports
const crunchFeaturePolicyHeader = require('../lib/crunchFeaturePolicyHeader')




import crunchFeaturePolicyHeader from '../src/lib/crunchFeaturePolicyHeader'

describe('crunchFeaturePolicyHeader', () => {
test('with single header', () => {
Expand Down
48 changes: 0 additions & 48 deletions __tests__/crunchHeaderValue.js

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
// Local imports
const crunchPermissionsPolicyHeader = require('../lib/crunchPermissionsPolicyHeader')




import crunchPermissionsPolicyHeader from '../src/lib/crunchPermissionsPolicyHeader'

describe('crunchPermissionsPolicyHeader', () => {
test('with single header', () => {
Expand Down
6 changes: 4 additions & 2 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
*/

module.exports = {
preset: 'ts-jest',

// Automatically clear mock calls and instances between every test
clearMocks: true,

Expand All @@ -14,8 +16,8 @@ module.exports = {
moduleDirectories: ['node_modules', 'shared'],

// An array of file extensions your modules use
moduleFileExtensions: ['js'],
moduleFileExtensions: ['ts', 'js'],

// A list of paths to modules that run some code to configure or set up the testing framework before each test
setupFilesAfterEnv: [],
};
}
11 changes: 0 additions & 11 deletions lib/PermissionsPolicy/index.js

This file was deleted.

0 comments on commit 91ba427

Please sign in to comment.