-
Notifications
You must be signed in to change notification settings - Fork 232
Set user agent for Angular, React, Vue libs - plus Jest #151
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import Auth from '../../src/Auth'; | ||
|
||
const pkg = require('../../package.json'); | ||
|
||
test('Auth component sets the right user agent on AuthJS', () => { | ||
const auth = new Auth({ | ||
issuer: 'https://foo/oauth2/default' | ||
}); | ||
const expectedUserAgent = `${pkg.name}/${pkg.version} okta-auth-js-`; | ||
expect(auth._oktaAuth.userAgent).toMatch(expectedUserAgent); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,15 +8,33 @@ | |
"src" | ||
], | ||
"scripts": { | ||
"prebuild": "npm run build:package-info", | ||
"prestart": "npm run build", | ||
"pretest": "npm run build && npm run build:harness", | ||
"prepublish": "npm run build", | ||
"test": "npm run --prefix test/e2e/harness/ test", | ||
"jest": "jest src/", | ||
"test": "npm run jest && npm run --prefix test/e2e/harness/ test", | ||
"start": "npm run --prefix test/e2e/harness/ start", | ||
"build": "rimraf dist/ && cross-env NODE_ENV=production webpack --config webpack.config.js --output-library-target=umd -p", | ||
"build:harness": "npm --prefix test/e2e/harness install", | ||
"build:package-info": "node ../../util/write-package-info.js . src/packageInfo.js", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should consider using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This task needs to be integrated into the build pipeline of each package, and ran locally while working on that specific package, so I'm not sure how lerna would help here? |
||
"lint": "eslint --ext .js,.vue src" | ||
}, | ||
"jest": { | ||
"moduleFileExtensions": [ | ||
"js", | ||
"json", | ||
"vue" | ||
], | ||
"transform": { | ||
"^.+\\.js$": "<rootDir>/node_modules/babel-jest", | ||
".*\\.(vue)$": "<rootDir>/node_modules/vue-jest" | ||
}, | ||
"moduleNameMapper": { | ||
"^@/(.*)$": "<rootDir>/src/$1" | ||
}, | ||
"mapCoverage": true | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/okta/okta-oidc-js.git" | ||
|
@@ -31,15 +49,17 @@ | |
}, | ||
"homepage": "https://github.com/okta/okta-oidc-js#readme", | ||
"dependencies": { | ||
"@okta/okta-auth-js": "^1.11.0", | ||
"@okta/okta-auth-js": "^1.14.0", | ||
"cross-env": "^5.1.1", | ||
"vue": "^2.5.9", | ||
"vue-router": "^3.0.1" | ||
}, | ||
"devDependencies": { | ||
"@vue/test-utils": "^1.0.0-beta.12", | ||
"autoprefixer": "^7.1.2", | ||
"babel-core": "^6.22.1", | ||
"babel-eslint": "^7.1.1", | ||
"babel-jest": "^23.0.0-alpha.0", | ||
"babel-loader": "^7.1.1", | ||
"babel-plugin-transform-runtime": "^6.22.0", | ||
"babel-preset-env": "^1.3.2", | ||
|
@@ -52,13 +72,16 @@ | |
"eslint-loader": "^1.7.1", | ||
"eslint-plugin-html": "^3.0.0", | ||
"eslint-plugin-import": "^2.7.0", | ||
"eslint-plugin-jest": "^21.15.0", | ||
"eslint-plugin-node": "^5.2.0", | ||
"eslint-plugin-promise": "^3.4.0", | ||
"eslint-plugin-standard": "^3.0.1", | ||
"jest": "^22.4.2", | ||
"nightwatch": "^0.9.12", | ||
"rimraf": "^2.6.2", | ||
"uglifyjs-webpack-plugin": "^1.1.1", | ||
"url-loader": "^0.5.8", | ||
"vue-jest": "^2.1.1", | ||
"vue-loader": "13.0.2", | ||
"vue-style-loader": "^3.0.1", | ||
"vue-template-compiler": "^2.5.2", | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import AuthJS from '@okta/okta-auth-js' | ||
import { createLocalVue } from '@vue/test-utils' | ||
import { default as Auth } from './Auth' | ||
|
||
const mockAuthJsInstance = {userAgent: 'foo'} | ||
const pkg = require('../package.json') | ||
|
||
jest.mock('@okta/okta-auth-js') | ||
|
||
AuthJS.mockImplementation(() => { | ||
return mockAuthJsInstance | ||
}) | ||
|
||
describe('Auth', () => { | ||
test('is a Vue plugin', () => { | ||
expect(Auth.install).toBeTruthy() | ||
}) | ||
test('sets the right user agent on AuthJS', () => { | ||
const expectedUserAgent = `${pkg.name}/${pkg.version} foo` | ||
createLocalVue().use(Auth, { | ||
issuer: '1', | ||
client_id: '2', | ||
redirect_uri: '3' | ||
}) | ||
expect(mockAuthJsInstance.userAgent).toMatch(expectedUserAgent) | ||
}) | ||
}) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
|
||
const workingDirectory = process.argv[2]; | ||
const destinationFile = process.argv[3]; | ||
const packageJsonPath = path.join(process.cwd(), workingDirectory, 'package.json') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing semicolon |
||
const configDest = path.join(process.cwd(), workingDirectory, destinationFile); | ||
const packageJson = require(packageJsonPath); | ||
const packageInfo = { | ||
name: packageJson.name, | ||
version: packageJson.version | ||
}; | ||
const output = 'export default ' + JSON.stringify(packageInfo, null, 2) + ';' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: There is no There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This util script is at the root, so not part of lerna. I can put together a PR to add eslint to the root, but we'd have to do testing to make sure it doesn't break what we just fixed for windows. |
||
|
||
console.log('Writing config to', configDest); | ||
|
||
fs.writeFileSync(configDest, output); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm leaning towards thinking we should prepend
npm run lint
to this command. That way we can start enforcing theeslint
style.