├── .editorconfig ├── .eslintignore ├── .eslintrc ├── .github └── workflows │ └── ci.yml ├── .gitignore ├── LICENSE ├── README.md ├── babel.config.js ├── commitlint.config.js ├── husky.config.js ├── jest.config.js ├── package.json ├── renovate.json ├── sdk └── OneSignalSDK.js ├── src ├── module.ts ├── options.ts ├── runtime │ └── plugin.js ├── types.ts └── utils.ts ├── test ├── fixture │ ├── .gitignore │ ├── nuxt.config.js │ ├── pages │ │ └── index.vue │ └── static │ │ ├── logo.png │ │ └── sw.js └── module.test.js ├── tsconfig.json └── yarn.lock /.editorconfig: -------------------------------------------------------------------------------- 1 | # editorconfig.org 2 | root = true 3 | 4 | [*] 5 | indent_size = 2 6 | indent_style = space 7 | end_of_line = lf 8 | charset = utf-8 9 | trim_trailing_whitespace = true 10 | insert_final_newline = true 11 | 12 | [*.md] 13 | trim_trailing_whitespace = false 14 | -------------------------------------------------------------------------------- /.eslintignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | dist 3 | .nuxt 4 | coverage 5 | test/fixture/static 6 | sdk 7 | src/runtime/plugin.js -------------------------------------------------------------------------------- /.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "extends": [ 3 | "@nuxtjs/eslint-config-typescript" 4 | ] 5 | } 6 | -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: ci 2 | 3 | on: 4 | push: 5 | branches: 6 | - master 7 | pull_request: 8 | branches: 9 | - master 10 | 11 | jobs: 12 | ci: 13 | runs-on: ${{ matrix.os }} 14 | 15 | strategy: 16 | matrix: 17 | os: [ubuntu-latest] 18 | node: [12] 19 | 20 | steps: 21 | - uses: actions/setup-node@v1 22 | with: 23 | node-version: ${{ matrix.node }} 24 | 25 | - name: Install apt dependencies 26 | run: sudo apt-get install libgbm1 27 | 28 | - name: checkout 29 | uses: actions/checkout@master 30 | 31 | - name: cache node_modules 32 | uses: actions/cache@v1 33 | with: 34 | path: node_modules 35 | key: ${{ matrix.os }}-node-v${{ matrix.node }}-deps-${{ hashFiles(format('{0}{1}', github.workspace, '/yarn.lock')) }} 36 | 37 | - name: Install dependencies 38 | if: steps.cache.outputs.cache-hit != 'true' 39 | run: yarn 40 | 41 | - name: Lint 42 | run: yarn lint 43 | 44 | - name: Test 45 | run: yarn test 46 | 47 | - name: Coverage 48 | uses: codecov/codecov-action@v1 49 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | *.iml 3 | .idea 4 | *.log* 5 | .nuxt 6 | .vscode 7 | .DS_Store 8 | coverage 9 | dist -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) pooya parsa 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # OneSignal Module 2 | 3 | [![npm version][npm-version-src]][npm-version-href] 4 | [![npm downloads][npm-downloads-src]][npm-downloads-href] 5 | [![Github Actions CI][github-actions-ci-src]][github-actions-ci-href] 6 | [![Codecov][codecov-src]][codecov-href] 7 | [![License][license-src]][license-href] 8 | 9 | OneSignal is a Free, high volume and reliable push notification service for websites and mobile applications. Setting and using this module is a little tricky as OneSignal requires to register its own Service worker. 10 | 11 | ## Setup 12 | 13 | 1. Follow steps to install [pwa module](https://pwa.nuxtjs.org) 14 | 15 | 2. Add `@nuxtjs/onesignal` dependency to your project 16 | 17 | ```bash 18 | yarn add @nuxtjs/onesignal # or npm install @nuxtjs/onesignal 19 | ``` 20 | 21 | 2. Add `@nuxtjs/onesignal` **BEFORE** `@nuxtjs/pwa` to the `modules` section of `nuxt.config`: 22 | 23 | ```js 24 | modules: [ 25 | '@nuxtjs/onesignal', 26 | '@nuxtjs/pwa' 27 | ] 28 | ``` 29 | 30 | 3. Add `oneSignal` options to `nuxt.config`: 31 | 32 | ```js 33 | // Options 34 | oneSignal: { 35 | init: { 36 | appId: 'YOUR_APP_ID', 37 | allowLocalhostAsSecureOrigin: true, 38 | welcomeNotification: { 39 | disable: true 40 | } 41 | } 42 | } 43 | ``` 44 | 45 | See references below for all `init` options. 46 | 47 | 4. Add `OneSignalSDK*` to `.gitignore` 48 | 49 | ## Async Functions 50 | This module exposes oneSignal as `$OneSignal` everywhere. So you can call it. 51 | Please note that because of async loading of OneSignal SDK script, every action should be pushed into `$OneSignal` stack. 52 | 53 | ```js 54 | // Inside page components 55 | this.$OneSignal.push(() => { 56 | this.$OneSignal.isPushNotificationsEnabled((isEnabled) => { 57 | if (isEnabled) { 58 | console.log('Push notifications are enabled!') 59 | } else { 60 | console.log('Push notifications are not enabled yet.') 61 | } 62 | }) 63 | }) 64 | 65 | // Using window and array form 66 | window.$OneSignal.push(['addListenerForNotificationOpened', (data) => { 67 | console.log('Received NotificationOpened:', data )} 68 | ]); 69 | ``` 70 | 71 | ## Change OneSignal SDK Script URL 72 | 73 | By default this modules ships with latest SDK dist. 74 | 75 | You can use recommended CDN by using `cdn: true` or changing it to a custom value using `OneSignalSDK`. 76 | 77 | ```js 78 | oneSignal: { 79 | // Use CDN 80 | cdn: true, 81 | 82 | // Use any custom URL 83 | OneSignalSDK: 'https://cdn.onesignal.com/sdks/OneSignalSDK.js' 84 | } 85 | ``` 86 | 87 | ## References 88 | 89 | - [Web Push SDK Reference](https://documentation.onesignal.com/docs/web-push-sdk) - Available options and API calls 90 | - [Customize Permission Messages](https://documentation.onesignal.com/docs/customize-permission-messages) 91 | - [Thanks for Subscribing Notifications](https://documentation.onesignal.com/docs/welcome-notifications) 92 | - [Product overview](https://documentation.onesignal.com/docs/product-overview) - More info about OneSignal 93 | - [Web Push SDK Setup](https://documentation.onesignal.com/docs/web-push-sdk-setup-https) - Setup guides for in-depth reading what this modules does. 94 | 95 | ## License 96 | 97 | [MIT License](./LICENSE) 98 | 99 | 100 | [npm-version-src]: https://img.shields.io/npm/v/@nuxtjs/onesignal/latest.svg 101 | [npm-version-href]: https://npmjs.com/package/@nuxtjs/onesignal 102 | 103 | [npm-downloads-src]: https://img.shields.io/npm/dt/@nuxtjs/onesignal.svg 104 | [npm-downloads-href]: https://npmjs.com/package/@nuxtjs/onesignal 105 | 106 | [github-actions-ci-src]: https://github.com/nuxt-community/onesignal-module/workflows/ci/badge.svg 107 | [github-actions-ci-href]: https://github.com/nuxt-community/onesignal-module/actions?query=workflow%3Aci 108 | 109 | [codecov-src]: https://img.shields.io/codecov/c/github/nuxt-community/onesignal-module.svg 110 | [codecov-href]: https://codecov.io/gh/nuxt-community/onesignal-module 111 | 112 | [license-src]: https://img.shields.io/npm/l/@nuxtjs/onesignal.svg 113 | [license-href]: https://npmjs.com/package/@nuxtjs/onesignal 114 | -------------------------------------------------------------------------------- /babel.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | presets: [ 3 | [ 4 | '@babel/preset-env', { 5 | targets: { 6 | esmodules: true 7 | } 8 | } 9 | ] 10 | ] 11 | } 12 | -------------------------------------------------------------------------------- /commitlint.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | extends: [ 3 | '@commitlint/config-conventional' 4 | ] 5 | } 6 | -------------------------------------------------------------------------------- /husky.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | hooks: { 3 | 'commit-msg': 'commitlint -E HUSKY_GIT_PARAMS', 4 | 'pre-commit': 'yarn lint', 5 | 'pre-push': 'yarn lint' 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /jest.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | testEnvironment: 'node', 3 | preset: '@nuxt/test-utils', 4 | collectCoverage: true, 5 | collectCoverageFrom: [ 6 | 'src/**', 7 | '!src/runtime/**' 8 | ] 9 | } 10 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@nuxtjs/onesignal", 3 | "version": "3.0.0", 4 | "description": "OneSignal module for Nuxt.js", 5 | "repository": "nuxt-community/onesignal-module", 6 | "license": "MIT", 7 | "contributors": [ 8 | { 9 | "name": "pooya parsa " 10 | } 11 | ], 12 | "main": "dist/module.js", 13 | "files": [ 14 | "dist", 15 | "sdk" 16 | ], 17 | "scripts": { 18 | "build": "siroc build && mkdist --src src/runtime --dist dist/runtime", 19 | "dev": "nuxt test/fixture", 20 | "format": "yarn lint --fix", 21 | "lint": "eslint --ext .js,.ts,.vue .", 22 | "release": "yarn test && standard-version && git push --follow-tags && npm publish", 23 | "test": "yarn lint && jest" 24 | }, 25 | "dependencies": { 26 | "defu": "^3.2.2", 27 | "hasha": "^5.2.0" 28 | }, 29 | "devDependencies": { 30 | "@babel/preset-env": "^7.12.11", 31 | "@babel/preset-typescript": "^7.12.7", 32 | "@commitlint/cli": "latest", 33 | "@commitlint/config-conventional": "latest", 34 | "@nuxt/test-utils": "^0.1.2", 35 | "@nuxt/types": "^2.14.12", 36 | "@nuxtjs/eslint-config-typescript": "^5.0.0", 37 | "@nuxtjs/pwa": "^3.3.4", 38 | "eslint": "^7.18.0", 39 | "husky": "^4.3.8", 40 | "jest": "^26.6.3", 41 | "mkdist": "^0.1.1", 42 | "nuxt-edge": "^2.15.0-26854632.498f8553", 43 | "playwright": "^1.8.0", 44 | "siroc": "^0.6.3", 45 | "standard-version": "latest" 46 | }, 47 | "publishConfig": { 48 | "access": "public" 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /renovate.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": [ 3 | "@nuxtjs" 4 | ] 5 | } 6 | -------------------------------------------------------------------------------- /sdk/OneSignalSDK.js: -------------------------------------------------------------------------------- 1 | !function(e){var t={};function n(o){if(t[o])return t[o].exports;var r=t[o]={i:o,l:!1,exports:{}};return e[o].call(r.exports,r,r.exports,n),r.l=!0,r.exports}n.m=e,n.c=t,n.d=function(e,t,o){n.o(e,t)||Object.defineProperty(e,t,{configurable:!1,enumerable:!0,get:o})},n.r=function(e){Object.defineProperty(e,"__esModule",{value:!0})},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=8)}([function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var o=function(){function e(t){var n=this;this.VERSION=Number(150900),this.log={setLevel:function(e){n.currentLogLevel=e}},this.setupStubFunctions(e.FUNCTION_LIST_TO_STUB,this.stubFunction,t),this.setupStubFunctions(e.FUNCTION_LIST_WITH_PROMISE_TO_STUB,this.stubPromiseFunction,t)}return e.prototype.setupStubFunctions=function(e,t,n){for(var o=this,r=function(e){if(n.indexOf(e)>-1)return"continue";Object.defineProperty(i,e,{value:function(){for(var n=[],r=0;r { 14 | addOneSignal.call(this, moduleOptions) 15 | } 16 | 17 | if (nuxt.options.mode === 'spa') { 18 | return hook() 19 | } 20 | 21 | nuxt.hook('build:before', hook) 22 | } 23 | 24 | function addOneSignal (moduleOptions) { 25 | const { nuxt, addPlugin } = this 26 | const { publicPath } = getRouteParams(nuxt.options) 27 | 28 | // Merge all options sources 29 | const options: ModuleOptions = defu( 30 | moduleOptions, 31 | nuxt.options.oneSignal, 32 | moduleDefaults 33 | ) 34 | 35 | // Define oneSignalSDK usage 36 | /* istanbul ignore next */ 37 | if (options.OneSignalSDK === undefined) { 38 | if (options.cdn) { 39 | // Use OneSignalSDK.js from CDN 40 | options.OneSignalSDK = 'https://cdn.onesignal.com/sdks/OneSignalSDK.js' 41 | } else { 42 | // Use OneSignalSDK.js from Sdk 43 | const OneSignalSDKJS = readFileSync(resolve(__dirname, '../sdk/OneSignalSDK.js')) 44 | const OneSignalSDKHash = hasha(OneSignalSDKJS) 45 | const OneSignalSDKFile = `ons.${OneSignalSDKHash}.js` 46 | 47 | options.OneSignalSDK = joinUrl(publicPath, OneSignalSDKFile) 48 | 49 | nuxt.options.build.plugins.push({ 50 | apply (compiler: any) { 51 | compiler.hooks.emit.tap('nuxt-pwa-onesignal', (compilation: any) => { 52 | compilation.assets[OneSignalSDKFile] = { 53 | source: () => OneSignalSDKJS, 54 | size: () => OneSignalSDKJS.length 55 | } 56 | }) 57 | } 58 | }) 59 | } 60 | } 61 | 62 | // Add the oneSignal SDK script to head 63 | if (!nuxt.options.head.script.find((script: any) => script.hid === 'onesignal')) { 64 | nuxt.options.head.script.push({ 65 | async: true, 66 | src: options.OneSignalSDK, 67 | hid: 'onesignal' 68 | }) 69 | } 70 | 71 | // Adjust manifest for oneSignal 72 | nuxt.options.manifest = options.manifest 73 | 74 | // Adjust swURL option of Workbox for oneSignal 75 | nuxt.options.workbox = options.workbox 76 | 77 | // Provide OneSignalSDKWorker.js and OneSignalSDKUpdaterWorker.js 78 | const makeSW = (name: string, scripts: Array) => { 79 | const workerScript = `importScripts(${scripts.map(i => `'${i}'`).join(', ')})\r\n` 80 | writeFileSync(resolve(nuxt.options.srcDir, 'static', name), workerScript, 'utf-8') 81 | } 82 | 83 | makeSW('OneSignalSDKWorker.js', [].concat(options.importScripts).concat(options.OneSignalSDK)) 84 | makeSW('OneSignalSDKUpdaterWorker.js', [options.OneSignalSDK]) 85 | 86 | // Add OneSignal plugin 87 | addPlugin({ 88 | src: resolve(__dirname, 'runtime/plugin.js'), 89 | ssr: false, 90 | fileName: join('onesignal.js'), 91 | options 92 | }) 93 | } 94 | 95 | oneSignalModule.meta = require('../package.json') 96 | 97 | export default oneSignalModule 98 | -------------------------------------------------------------------------------- /src/options.ts: -------------------------------------------------------------------------------- 1 | export interface WelcomeNotification { 2 | disable: boolean 3 | } 4 | 5 | export interface ModuleOptionsInit { 6 | allowLocalhostAsSecureOrigin: boolean 7 | welcomeNotification: WelcomeNotification 8 | } 9 | 10 | export interface ModuleManifest { 11 | name: string 12 | 'short_name': string 13 | 'start_url': string 14 | display: string 15 | 'gcm_sender_id': string 16 | } 17 | 18 | export interface ModuleOptions { 19 | OneSignalSDK: string 20 | cdn: boolean 21 | importScripts: Array 22 | init: ModuleOptionsInit 23 | manifest: ModuleManifest, 24 | workbox: { 25 | swURL: string 26 | } 27 | } 28 | 29 | export const moduleDefaults: ModuleOptions = { 30 | OneSignalSDK: undefined, 31 | cdn: true, 32 | importScripts: [ 33 | '/sw.js?' + Date.now() 34 | ], 35 | manifest: { 36 | name: '', 37 | short_name: '', 38 | start_url: '/', 39 | display: 'standalone', 40 | gcm_sender_id: '482941778795' 41 | }, 42 | init: { 43 | allowLocalhostAsSecureOrigin: true, 44 | welcomeNotification: { 45 | disable: true 46 | } 47 | }, 48 | workbox: { 49 | swURL: 'OneSignalSDKWorker.js' 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/runtime/plugin.js: -------------------------------------------------------------------------------- 1 | window.$OneSignal = window.OneSignal = window.OneSignal || []; 2 | 3 | OneSignal.push(['init', <%= JSON.stringify(options.init, null, 2) %>]) 4 | 5 | export default function (ctx, inject) { 6 | inject('OneSignal', OneSignal) 7 | } 8 | -------------------------------------------------------------------------------- /src/types.ts: -------------------------------------------------------------------------------- 1 | import type { } from '@nuxt/types' 2 | import type OneSignal from '../' 3 | 4 | declare module '@nuxt/types' { 5 | interface Context { 6 | $OneSignal: OneSignal 7 | } 8 | interface NuxtAppOptions { 9 | $OneSignal: OneSignal 10 | } 11 | } 12 | 13 | declare module 'vue/types/vue' { 14 | interface Vue { 15 | $OneSignal: OneSignal 16 | } 17 | } 18 | 19 | declare module 'vuex/types/index' { 20 | // eslint-disable-next-line 21 | interface Store { 22 | $OneSignal: OneSignal 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/utils.ts: -------------------------------------------------------------------------------- 1 | import { posix as path } from 'path' 2 | import { NuxtOptions } from '@nuxt/types' 3 | 4 | export function joinUrl (...args: string[]) { 5 | return path.join(...args).replace(':/', '://') 6 | } 7 | 8 | export function isUrl (url: string) { 9 | return url.indexOf('http') === 0 || url.indexOf('//') === 0 10 | } 11 | 12 | export function getRouteParams (options: NuxtOptions) { 13 | // routerBase 14 | const routerBase = options.router.base 15 | 16 | // publicPath 17 | let publicPath 18 | if (isUrl(options.build.publicPath)) { 19 | publicPath = options.build.publicPath 20 | } else { 21 | publicPath = joinUrl(routerBase, options.build.publicPath) 22 | } 23 | 24 | return { 25 | routerBase, 26 | publicPath 27 | } 28 | } 29 | 30 | module.exports = { 31 | joinUrl, 32 | getRouteParams 33 | } 34 | -------------------------------------------------------------------------------- /test/fixture/.gitignore: -------------------------------------------------------------------------------- 1 | OneSignalSDK* 2 | -------------------------------------------------------------------------------- /test/fixture/nuxt.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | srcDir: __dirname, 3 | render: { 4 | resourceHints: false 5 | }, 6 | modules: [ 7 | '@nuxtjs/pwa', 8 | '../../src/module.ts' 9 | ], 10 | oneSignal: { 11 | init: { 12 | appId: 'd867ac26-f7be-4c62-9fdd-b756a33c4a8f' 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /test/fixture/pages/index.vue: -------------------------------------------------------------------------------- 1 | 6 | 7 | 11 | -------------------------------------------------------------------------------- /test/fixture/static/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuxt-community/onesignal-module/481849c3487c1b8ec172797a2ad59dd0c1108077/test/fixture/static/logo.png -------------------------------------------------------------------------------- /test/fixture/static/sw.js: -------------------------------------------------------------------------------- 1 | // THIS FILE SHOULD NOT BE VERSION CONTROLLED 2 | -------------------------------------------------------------------------------- /test/module.test.js: -------------------------------------------------------------------------------- 1 | import { setupTest, expectModuleToBeCalledWith, createPage } from '@nuxt/test-utils' 2 | 3 | describe('default configuration', () => { 4 | setupTest({ 5 | testDir: __dirname, 6 | fixture: 'fixture', 7 | server: true, 8 | config: { 9 | oneSignal: { 10 | init: { 11 | appId: 'd867ac26-f7be-4c62-9fdd-b756a33c4a8f' 12 | } 13 | } 14 | } 15 | }) 16 | 17 | test('should inject plugin', () => { 18 | expectModuleToBeCalledWith('addPlugin', expect.objectContaining({ 19 | fileName: 'onesignal.js' 20 | })) 21 | }) 22 | }) 23 | 24 | describe('spa configuration', () => { 25 | setupTest({ 26 | testDir: __dirname, 27 | fixture: 'fixture', 28 | server: true, 29 | config: { 30 | mode: 'spa', 31 | oneSignal: { 32 | init: { 33 | appId: 'd867ac26-f7be-4c62-9fdd-b756a33c4a8f' 34 | } 35 | } 36 | } 37 | }) 38 | }) 39 | 40 | describe('default one signal sdk', () => { 41 | setupTest({ 42 | testDir: __dirname, 43 | fixture: 'fixture', 44 | server: true, 45 | config: { 46 | mode: 'spa', 47 | oneSignal: { 48 | cdn: false, 49 | init: { 50 | appId: 'd867ac26-f7be-4c62-9fdd-b756a33c4a8f' 51 | } 52 | } 53 | } 54 | }) 55 | }) 56 | 57 | describe('define onesignal script into head section', () => { 58 | setupTest({ 59 | testDir: __dirname, 60 | fixture: 'fixture', 61 | server: true, 62 | config: { 63 | head: { 64 | script: [ 65 | { hid: 'onesignal', name: 'One signal script', src: 'https://cdn.onesignal.com/sdks/OneSignalSDK.js' } 66 | ] 67 | }, 68 | oneSignal: { 69 | cdn: false, 70 | init: { 71 | appId: 'd867ac26-f7be-4c62-9fdd-b756a33c4a8f' 72 | } 73 | } 74 | } 75 | }) 76 | }) 77 | 78 | describe('define build public path', () => { 79 | setupTest({ 80 | testDir: __dirname, 81 | fixture: 'fixture', 82 | server: true, 83 | build: { 84 | publicPath: '/_onesignal/' 85 | }, 86 | config: { 87 | oneSignal: { 88 | cdn: false, 89 | init: { 90 | appId: 'd867ac26-f7be-4c62-9fdd-b756a33c4a8f' 91 | } 92 | } 93 | } 94 | }) 95 | }) 96 | 97 | describe('define onesignal manifest', () => { 98 | setupTest({ 99 | testDir: __dirname, 100 | fixture: 'fixture', 101 | server: true, 102 | config: { 103 | oneSignal: { 104 | manifest: { 105 | name: 'Awesome website' 106 | }, 107 | cdn: false, 108 | init: { 109 | appId: 'd867ac26-f7be-4c62-9fdd-b756a33c4a8f' 110 | } 111 | } 112 | } 113 | }) 114 | }) 115 | 116 | describe('browser', () => { 117 | setupTest({ 118 | testDir: __dirname, 119 | fixture: 'fixture', 120 | browser: true 121 | }) 122 | 123 | test('should render index page', async () => { 124 | const page = await createPage('/') 125 | const body = await page.innerHTML('body') 126 | expect(body).toContain('Works!') 127 | }) 128 | }) 129 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "ESNext", 4 | "module": "ESNext", 5 | "esModuleInterop": true, 6 | "moduleResolution": "node", 7 | "types": [ 8 | "node", 9 | "jest" 10 | ] 11 | } 12 | } 13 | --------------------------------------------------------------------------------