-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Upgrade analytics.js to analytics-next (browser SDK) (#297)
- Loading branch information
Showing
13 changed files
with
1,192 additions
and
287 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -91,3 +91,7 @@ test-env/** | |
|
||
# intelliJ | ||
.idea | ||
|
||
|
||
# all build artifacts | ||
**/build/** |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// eslint-disable-next-line no-undef | ||
const supressLog = (...args) => { | ||
// avoid Warning: No API token found at test-env/build | ||
if (typeof args[0] === 'string' && args[0].includes('API token')) { | ||
return undefined | ||
} else { | ||
console.error(...args) | ||
} | ||
} | ||
|
||
console.error = supressLog |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Type definition "integration" tests for the typescript SDKs | ||
|
||
``` | ||
npx ts-node src/__tests__/ts-typedef-tests/run.ts | ||
``` | ||
These tests confirm: | ||
- That the typescript clients have no type errors | ||
- That the typescript clients typings behaves as expected | ||
|
||
Running the tests... | ||
1. Build typescript client using cli | ||
2. Imports that client into a type definition test that asserts that it's typed correctly | ||
3. Type checks both the client (artifact) and the type definition |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import fs from "node:fs"; | ||
import path from "node:path"; | ||
import { setupEnv } from "../__helpers__/environment"; | ||
import { run } from "../__helpers__/oclif-runner"; | ||
|
||
const TEST_ENV_PATH = "production"; | ||
|
||
const configurations = [ | ||
["typescript", "analytics-node", "segment.ts"], | ||
["typescript", "analytics-js", "segment.ts"], | ||
]; | ||
|
||
export const buildSDKs = async () => { | ||
for (const config of configurations) { | ||
const [language, sdk, filename, plan, id, outputPath, legacyId] = config; | ||
const testPath = await setupEnv( | ||
TEST_ENV_PATH, | ||
language, | ||
sdk, | ||
plan, | ||
id, | ||
outputPath, | ||
legacyId | ||
); | ||
await run(["production", "-c", testPath]); | ||
// basically, we write the test files to a new build path relative to this script. | ||
// typechecking ./test-env directly is a little complicated because of .tsconfig configuration + hashed directory name | ||
const output = fs | ||
.readFileSync(path.join(testPath, filename), { | ||
encoding: "utf-8", | ||
}) | ||
.replace(/version:.*\d.*/g, ""); | ||
|
||
const BUILD_PATH = path.resolve(__dirname, "build"); | ||
if (!fs.existsSync(BUILD_PATH)) { | ||
fs.mkdirSync(BUILD_PATH); | ||
} | ||
fs.writeFileSync( | ||
path.resolve(BUILD_PATH, `${language}-${sdk}.ts`), | ||
output, | ||
{ encoding: "utf-8" } | ||
); | ||
} | ||
}; |
Oops, something went wrong.