Skip to content
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

test(typescript): code in src sub-directory #682

Merged
merged 2 commits into from
Dec 7, 2020
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
69 changes: 69 additions & 0 deletions packages/typescript/test/fixtures/src-dir/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
type FormDataMap = Map<string, string[]>;

class ReadOnlyFormData {
map: FormDataMap;

constructor(map: FormDataMap) {
this.map = map;
}

get(key: string) {
return this.map.get(key)?.[0];
}

getAll(key: string) {
return this.map.get(key);
}

has(key: string) {
return this.map.has(key);
}

*[Symbol.iterator]() {
for (const [key, value] of this.map) {
for (let i = 0; i < value.length; i += 1) {
yield [key, value[i]];
}
}
}

*entries() {
for (const [key, value] of this.map) {
for (let i = 0; i < value.length; i += 1) {
yield [key, value[i]];
}
}
}

*keys() {
for (const [key, value] of this.map) {
for (let i = 0; i < value.length; i += 1) {
yield key;
}
}
}

*values() {
for (const [, value] of this.map) {
for (let i = 0; i < value.length; i += 1) {
yield value;
}
}
}
}

export default function() {
const map: FormDataMap = new Map();

return {
append(key: string, value: string) {
if (map.has(key)) {
(map.get(key) as string[]).push(value);
} else {
map.set(key, [value]);
}
},

data: new ReadOnlyFormData(map)
};
}
24 changes: 24 additions & 0 deletions packages/typescript/test/fixtures/src-dir/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"compilerOptions": {
"lib": ["es2020"],
"outDir": "dist",
"target": "es2020",

"skipLibCheck": true,
"declaration": true,

"noEmitOnError": true,
"noErrorTruncation": true,

"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"allowSyntheticDefaultImports": true,

"strict": true,
"noImplicitThis": true,
"noUnusedLocals": true,
"noUnusedParameters": true
},
"exclude": ["node_modules"]
}
28 changes: 28 additions & 0 deletions packages/typescript/test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1181,6 +1181,34 @@ test.serial('picks up on newly included typescript files in watch mode', async (
t.true(usage, 'should contain usage');
});

// TODO: upgrade TypeScript when there is a release containing the fix for this issue
// https://github.com/microsoft/TypeScript/pull/41811. Then enable this test
// More details at https://github.com/rollup/plugins/issues/287. This fails with the message:
// Unexpected token (Note that you need plugins to import files that are not JavaScript)
test.serial.skip('works when code is in src directory', async (t) => {
const bundle = await rollup({
input: 'fixtures/src-dir/src/index.ts',
output: [
{
dir: 'fixtures/src-dir/dist',
format: 'esm'
}
],
plugins: [
typescript({
tsconfig: 'fixtures/src-dir/tsconfig.json'
})
],
onwarn
});
const output = await getCode(bundle, { format: 'esm', dir: 'fixtures/src-dir/dist' }, true);

t.deepEqual(
output.map((out) => out.fileName),
['index.js', 'types/index.d.ts', 'types/index.d.ts.map']
);
});

function waitForWatcherEvent(watcher, eventCode) {
return new Promise((resolve, reject) => {
watcher.on('event', function handleEvent(event) {
Expand Down